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.

No comments:

Post a Comment

How to register multiple implementations of the same interface in Asp.Net Core?

 Problem: I have services that are derived from the same interface. public interface IService { } public class ServiceA : IService { ...