How to render an HTML attribute from a Razor view.
- by ProfK
I would like to use the same partial view for create, edit, and details views, to avoid duplicating the fieldset structure for an entity. Then, depending on which view renders the partial view, I would like to add a class of "read-only" to a div surrounding my fieldset and handle making the actual input fields read-only on the client, using css or jQuery, or whatever. How can I specify from my Razor view that I need this class added to the "item-details" div?
<div class="item-details">
<fieldset>
<legend>Product Details</legend>
@Html.HiddenFor(model => model.DetailItem.ProductId)
<div class="editor-label">
@Html.LabelFor(model => model.DetailItem.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DetailItem.Name)
@Html.ValidationMessageFor(model => model.DetailItem.Name)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
</div>