Html.EditorFor<> equivalent for viewing read-only data?

StrictlySocial picture StrictlySocial · Feb 21, 2011 · Viewed 37.5k times · Source

I am currently using the Html.EditorFor<> method for generating editor fields, however I would like to use something similar for displaying field information in a read-only format such as a details page, i.e. a label with the field name followed by a label with the field value.

Is there currently any equivalent in MVC for generating this? Or am I going to have to create a custom helper?

Thanks in advance.

Edit: I am aware of DisplayFor and LabelFor, is it just a case of manually having to combine these?

Answer

zihotki picture zihotki · Feb 21, 2011

Use

<%= Html.DisplayFor(model => model.Property) %>

Or if you want to see a readonly(disabled) textbox

<%= Html.TextBoxFor(model => model.Property, new { disabled="disabled", @readonly = "readonly" })%>