I'm trying to display a view model using an editor template that wraps the model in a fieldset before applying a base Object editor template.
My view:
@model Mvc3VanillaApplication.Models.ContactModel
@using (Html.BeginForm())
{
@Html.EditorForModel("Fieldset")
}
Uses a fieldset template (Views/Shared/EditorTemplates/Fieldset.cshtml):
<fieldset>
<legend>@ViewData.ModelMetadata.DisplayName</legend>
@Html.EditorForModel()
</fieldset>
Which in turn uses a basic template for all objects (Views/Shared/EditorTemplates/Object.cshtml):
@foreach (var prop in ViewData.ModelMetadata.Properties.Where(x =>
x.ShowForEdit && !x.IsComplexType && !ViewData.TemplateInfo.Visited(x)))
{
@Html.Label(prop.PropertyName, prop.DisplayName)
@Html.Editor(prop.PropertyName)
}
That's my intent anyway. The problem is that while the page renders with a fieldset and a legend, the Object template isn't applied so no input controls are displayed.
If I change the view to not specify the "Fieldset" template then my model's properties are rendered using the Object template, so it's not that my Object template can't be found.
Is it possible to pass the same model through multiple templates?
For what it's worth, the view model looks like this:
namespace Mvc3VanillaApplication.Models
{
[System.ComponentModel.DisplayName("Contact Info")]
public class ContactModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}