ASP.NET MVC 3: hidden field in cshtml:
Consider the following ViewModel class:
Now you want the edit page to store the ID but have it not be seen:
Which results in the equivalent of the following HTML:
Please share this post with your friends. If it's useful to you. Thanks!.
From your model you can creates from your modela hidden input on the form for the field that you pass it.
It is useful for fields in your Model/ViewModel that you need to persist on the page and have passed back when another call is made but shouldn't be seen by the user.
public class ViewModeStudent { public string Value { get; set; } public int Id { get; set; } }
Now you want the edit page to store the ID but have it not be seen:
<% using(Html.BeginForm() { %> <%= Html.HiddenFor(model.Id) %><br /> <%= Html.TextBoxFor(model.Value) %> <% } %>
<form name="form1"> <input type="hidden" name="Id">2</input> <input type="text" name="Value" value="Some Text" /> </form>
0 comments:
Post a Comment
Share your thoughts here...