Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML.HiddenFor value set

@Html.HiddenFor(model => model.title, new { id= "natureOfVisitField", @value = '@Model.title'}) 

it doesen't work! how to set the value?

like image 536
arnoldrob Avatar asked Sep 03 '12 13:09

arnoldrob


People also ask

What does HTML HiddenFor do?

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.

How can get hidden field value in MVC controller?

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.

What is hidden field in MVC?

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.


1 Answers

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

like image 176
user1187093 Avatar answered Sep 28 '22 03:09

user1187093