I am trying to call a function but I am getting - Uncaught ReferenceError: SetNavStateToX not defined.
JavaScript
@Scripts.Render("~/bundles/jquery")
@Styles.Render("~/Content/css")
@switch (@Session["NavState"])
{
case "Exists":
Welcome back @Session["UserName"].
I hope you are back because you enjoy the forum and blog and what it has to offer.
@* NOTE: this one works fine. *@
@*
$.post("UserProfile/SetSessionVar", { variable: "NavState" });
*@
SetNavStateToX();
break;
default:
break;
}
function SetNavStateToX() {
$.ajax({
type: 'POST',
url: '@Url.Action("SetSessionVar", "UserProfile")',
data: { variable: "NavState" },
success: function () {
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Critical Error: something is wrong in the call to SetNavStateToXStatus: " + xhr.status + ". Error: " + thrownError.toString() + ". Response Text: " + xhr.responseText);
}
})
}
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Jan 20, 2022, 12:57 PM EST