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?