How to render an HTML attribute from a Razor view.

Posted by ProfK on Stack Overflow See other posts from Stack Overflow or by ProfK
Published on 2010-12-16T17:24:20Z Indexed on 2010/12/29 22:53 UTC
Read the original article Hit count: 244

Filed under:
|
|

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>

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about asp.net-mvc-3