Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 851
StrictlySocial Avatar asked Feb 21 '11 12:02

StrictlySocial


People also ask

What is HTML EditorFor?

The Html. Editor() or Html. EditorFor() extension methods generate HTML elements based on the data type of the model object's property. The following table list the data types and releted HTML elements: DataType.

What is the use of EditorFor in MVC?

EditorFor<TModel,TValue>(HtmlHelper<TModel>, Expression<Func<TModel,TValue>>, String, String, Object) Returns an HTML input element for each property in the object that is represented by the expression, using the specified template, HTML field name, and additional view data.


1 Answers

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" })%>
like image 158
zihotki Avatar answered Nov 15 '22 23:11

zihotki