Just wondering how and when people are using Editor/Display Templates vs. Html Helpers. Specifically I am talking about its use in rendering different UI control rather than rendering entities.
For instance, I have something like the following atm:
<tr>
<th><%= Html.LabelFor(x => x.ActivityTypeId) %></th>
<td><%= Html.EditorFor(x => x.ActivityTypeList, "MultiSelectDropDownList")%></td>
</tr>
<tr>
<th><%= Html.LabelFor(x => x.Name) %></th>
<td><%= Html.EditorFor(x => x.Name) %></td>
</tr>
<tr>
<th><%= Html.LabelFor(x => x.Description) %></th>
<td><%= Html.DisplayFor(x => x.Description, "DisplayString")%></td>
</tr>
But of late I am wondering if I should be doing this:
<tr>
<th><%= Html.LabelFor(x => x.ActivityTypeId) %></th>
<td><%= Html.MultiSelectDropDownList(x => x.ActivityTypeList)%></td>
</tr>
<tr>
<th><%= Html.LabelFor(x => x.Name) %></th>
<td><%= Html.EditorFor(x => x.Name) %></td>
</tr>
<tr>
<th><%= Html.LabelFor(x => x.Description) %></th>
<td><%= Html.DisplayString(x => x.Description)%></td>
</tr>
But if I go with this second option is there much point of using the middle editor for... I would be just a well off using Html.Textbox and have the benefit of being able to set any html property I like.
I'm interested what patterns people are using here... Any ideas?
Cheers Anthony
EditorFor and DisplayFor are the most powerful aspects of MVC 2 and in my opinion should be used and abused as much as possible.
Hop over to Brad Wilsons blog and check out how you can extend the Object templates to quickly whip out convention based screens from ViewModels decorated with attributes: http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-5-master-page-templates.html
I'm using this technique in a current project and so far not one line of HTML has even been written for an individual screen. :D
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