I want to change the following variable to false using the onclick method of a button in my shared navbar.
Variable
public static bool LoginStatus { get; set; } = true;
What I have so far which does not work:
Html button
<button type="button" onclick=@Apex_Leaderboard_Website.Models.LoginViewModel.LoginStatus = false>Log Out</button>
I have tried a form but with the button in the shared navbar it makes it difficult to submit it to the appropriate handler.
CodePudding user response:
you should use asp:Button
because you want to modify a C# class property. then you can OnClick event on it so that you will be able to call a backend(code-behind) method and in that method, you can set the enter code here
to false
.
Here is the reference for you.
CodePudding user response:
You can use posting a form or use js.
<form method="post" asp-route-LoginStatus=false>
<input type="submit" value="Log Out" />
</form>
js:
<button type="button" onclick="passData()">Log Out</button>
function passData() {
$.ajax({
type: "POST",
url: "xxx",
data: { LoginStatus: false },
success: function(data) {
}
});
}
action:
public ActionResult xxx(bool LoginStatus)
{
....
}