How should I organize my mvc templates?
- by CatZ
Hi,
In the new version of MVC we have been given display and editor templates. I was wondering how to make the best possible use of these. I was at first thinking in the line of creating one for a collection and one for an item in the case I want to display either as a list or single but it does not really make sense to me. I'll show you what I mean and please comment if this is wrong. I have trouble figuring it out myself.
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<DisplayPhoneModel>>" %>
<% foreach (var item in Model){%>
<%= Html.DisplayFor(x => item) %>
<%}%>
So in my tiny reality that would for every item in the model search for a display template for DisplayPhoneModel. That display template could then simply look like.
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DisplayPhoneModel>" %>
<%= Html.LabelFor(x => x.PhoneType) %> <%= Html.LabelFor(x => x.PhoneNumber) %>
So, question is if there is a better way to handle this? Am I at all on the right path?