I have a hidden asp.net MVC control in the form:
<%= Html.HiddenFor(m => m.NodeId) %>
My JavaScript / jQuery code:
var DeleteEntireItem = '<% = btnDeleteEntireMenu.ClientID%>';
var Node;
debugger;
$('#' + DeleteEntireItem).click(function () {
Node = NodeValue;
document.forms[0].submit();
});
How can I assign the value of variable 'Node' to the asp.net MVC hidden control?
HiddenFor<TModel,TProperty>(HtmlHelper<TModel>, Expression<Func<TModel,TProperty>>, IDictionary<String,Object>) Returns an HTML hidden input element for each property in the object that is represented by the specified expression, using the specified HTML attributes.
You can set the value attribute of a hidden input tag by selecting it using the property name and using the jquery val() method.
In your case this becomes:
$("#NodeId").val(Node)
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