I have a couple of MVC4 projects, and I'd like to make a set of display / editor templates that are reused across these projects. I'd like to create a common project that contains these templates, and reference it in the other projects.
So I have the views defined in my common project, along with some other utilities:
Common
- Models
- CommonMetadataAttribute.cs
- Views
- Shared
- EditorTemplates
- Decimal.cshtml
- Object.cshtml
- Password.cshtml
- String.cshtml
- Switch.cshtml
- ViewTemplates
- Object.cshtml
- Switch.cshtml
- Error.cstml
And in my client project's models I'd have
using MobileWeb.Common
public class MyViewModel
{
[UIHint("Switch")]
[CommonMetadata(Theme = "foo")]
public bool Enable { get; set; }
}
And in the client projects views I'd be able to generate my custom editors by simply calling:
@model MyViewModel
...
@Html.EditorFor(model => model.Enable)
Ideally, the client projects could override with their own templates, and it would just fall back to the common templates if no project-specific one was defined.
I've considered MvcContrib's portable areas, but I'm not sure if it will work since this is not really an area and I don't really know how to go about setting it up. Before I go down that road I'd like to know what is the preferred way of doing this?