0

I have the following typescript in a file called Link.ts:

interface LinkConfig {
    token: string;
    url: string;
    redirectUrl: string;
}

async function postData(config: LinkConfig): Promise<void> {
    const postObject = {
        deviceToken: config.token,
        isLink: true
    };

    try {
        const result: any = await callRestEndpoint(config.url, 'POST', postObject);
        console.log("Post success:", result);

        const resultElement = document.getElementById("result");
        if (resultElement) {
            resultElement.appendChild(document.createTextNode(JSON.stringify(result)));
        }

        if (result.success) {
            window.location.href = config.redirectUrl;
        }
    } catch (error) {
        console.error("Post failed:", error);
        const resultElement = document.getElementById("result");
        if (resultElement) {
            resultElement.appendChild(document.createTextNode(JSON.stringify(error)));
        }
    }
}

In my ASP.NET MVC page model (the project is using Razor pages, not .cshtml) How do I pass my token, url and redirecturl into the Typescript object and then into the Typescript function?

1 Answer 1

0

Typescript compiles to JavaScript. You should have a file called Link.js. Reference that in your page like any other JS file, and call the postData method:

<script>
    await postData({token: 'your token', url: 'your url', redirectUrl: 'your redirectUrl' });
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.