Is it possible to access the javascript variable inside razor syntax?
Here is my code
$("#add-user-to-plan").click(function () {
var userListId = $("#user-list").val();
@{
Model.Users.Add(userListId );
}
});
When I click the add-user-to-plan button it will add an item to a list of Users.
In your Razor create a hidden field
@Html.HiddenFor(model => model.userListId , new { id = "userListIdHidden" });
In java script assign the value for userListIdHidden
$("#add-user-to-plan").click(function () {
var userListId = $("#user-list").val();
document.getElementById("userListIdHidden").value = userListId;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With