@Html.HiddenFor(model => model.title, new { id= "natureOfVisitField", @value = '@Model.title'})
it doesen't work! how to set the value?
Html. HiddenFor<TModel, TProperty> extension method is a strongly typed extension method generates a hidden input element for the model property specified using a lambda expression.
There are two Hidden Fields. The Hidden Field for the Name value is created using Html. HiddenFor function while the Hidden Field for the Country value is created using Html. Hidden helper function and it is assigned value using ViewBag object.
Here we will learn how to create or use hidden fields in asp.net mvc with a simple example using HTML helpers. Before going in-depth, let's understand the definition of hidden fields. The hidden fields are controls that allow us to store data or information on a page without displaying it.
For setting value in hidden field do in the following way:
@Html.HiddenFor(model => model.title, new { id= "natureOfVisitField", Value = @Model.title})
It will work
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