I’m using MVC Razor and when I try to edit something, I pass it through a ViewModel it contains all of the necessary information, I have tested this.
Here is my View:
<div class="editor-label">
@Html.LabelFor(model => model.CollectionId)
</div>
<div class="editor-field">
@Html.DisplayFor(model => model.CollectionId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.BrandName)
</div>
<div class="editor-field">
@Html.DisplayFor(model => model.BrandName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Season)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Season)
@Html.ValidationMessageFor(model => model.Season)
</div>
As you can see, I am only using @Html.EditorFor on the information that they can change as this is all I want to change. But I feel its necessary to show them the other information just so they know exactly what they are editing.
My question is, how I can I achieve the equivalent of an @Html.EditorFor passing back the information, without actually allowing them to edit it?
you have to use Html.HiddenFor to pass their values back to the controller.
e.g.