The project is currently MVC3 but could be upgraded if required.
I'm trying to get a content editor for a simple cms improved. At the moment we use
@Html.EditorFor(model=>model.Content) //Content is a List<EditableContent>
EditableContent has a (brand new) property of string EditorView. The idea is this will name suitable editors for particular items of content.
What I want to do is use my default EditableContent template if EditorView is null, otherwise use the EditorView as the named template. I'm aware of the overload for EditorFor that takes a template, but that's going to use the same template for each item of content, but that's not what I want.
I did try taking my default template and basically doing
//Shared/EditorTemplates/EditableContent.cshtml
@model Website.Areas.Admin.EditableContent
@if (!string.IsNullOrWhiteSpace(Model.EditorView))
{
<text>
@Model.EditorView
@Html.EditorForModel(Model.EditorView)
</text>
}
else
{
//Original template
}
Weirdly in this case, the view is located (I have a slightly custom view engine which appears to locate the view correctly). The name of the view (via @Model.EditorView ) is emitted to the page, but @Html.EditorForModel() doesn't produce anything.
Any ideas how I can use a custom template per item using EditorFor or similar ?