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?
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.
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.
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" })%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With