Access javascript variable inside razor
13,207
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;
});
Author by
Ramppy Dumppy
Updated on June 26, 2022Comments
-
Ramppy Dumppy almost 2 years
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.
-
dsgriffin about 10 years
-
-
Ramppy Dumppy about 10 years@Golda.. Thank you so much for the help..
-
Bigeyes almost 7 yearsBad solution. Get exception async...