ASP.NET MVC > View - Form specific

Element in ASP.NET MVC view in ASP.NET MVC

How to create a hidden form element in ASP.NET MVC view?


To create hidden form element in Razor markup, we follow approach depending on scenario.
If we just need to create a hidden form element, we use @Html.Hidden html helper method.

@Html.Hidden("Name", "Value Optional") 

If the hidden element needs to be created for the property of the Model in the view, we can use @Html.HiddenFor html helper method.

@Html.HiddenFor(model => model.AutoId)

In some scenario, we can also use

<input type="hidden" name="myHiddendData" value="@Model.AutoId" />

Here, the value of the AutoId from the model will be stored into the myHiddenData hidden element.

Remember that all these code must be written inside the html form element.

 Views: 19455 | Post Order: 26



Write for us






Hosting Recommendations