I want to set TempData in View Component so that i can check it in Login Action when there is error in View Component.
Here is my .ts file code
window.onload = function () {
fetch('../Controller/ActionName',
{
headers: {
RequestVerificationToken: (<HTMLInputElement>document.getElementById("Token")).value
}
})
.then((response) => {
if (response.status != 200) {
redirectToHomePage();
}
response.text().then((data) => {
document.getElementById("Id")!.innerHTML = data;
});
});
// Redirect to home page
function redirectToHomePage() {
var url = window.location.origin;
window.location.href = url + '/Login/Login/';
}
};
Below is the ViewComponent code
public IViewComponentResult TestViewComponent()
{
try
{
// Do code here
}
Catch(Exception ex){
TempData["Error"] = "Err msg";
return View(viewName)
}
return View(viewName);
}
TempData is set correctly in ViewComponent, but when response get back from .ts file from redirectToHomePage() function to Login/Login TempData will be null.
So how to get TempData in Login action
Thank you in advance