If I have a the following model
public class User
{
public List<Company> Companies;
[Required]
[DisplayName("Login")]
public string Login { get; set; }
[Required]
[DisplayName("First Name")]
public string FirstName { get; set; }
[Required]
[DisplayName("Last Name")]
public string LastName { get; set; }
[Required]
[DisplayName("Password")]
public string Password { get; set; }
[Required]
[DisplayName("Company")]
private int Company { get; set; }
}
And the following generic control template writer (which would have to be extended appropriately)
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<% foreach (var prop in ViewData.ModelMetadata.Properties .Where(pm => pm.ShowForEdit && !ViewData.TemplateInfo.Visited(pm)))
{ %>
<div class="SD_FieldItem">
<% if (!String.IsNullOrEmpty(Html.Label(prop.PropertyName).ToHtmlString()))
{
switch (prop.ModelType.Name)
{
case "Boolean":
%>
<div class="SD_BoolField">
<%= Html.CheckBox(prop.PropertyName) %>
<%= Html.Label(prop.PropertyName) %>
<%= Html.ValidationMessage(prop.PropertyName,
View Complete Post