I have a class called LocalizedString
that is defined in an external library that is referenced in my asp.net mvc 3 project.
I have created an editor template called LocalizedString.cshtml
in the ~\View\Shared\EditorTemplates
folder.
I have the following model
public class Region
{
public LocalizedString Title { get; set; }
}
I have the following test page:
@model Region
@Html.EditorForModel()
@Html.EditorFor(x => x.Title)
The editor template for LocalizedString
is not invoked when I call EditorForModel
, but it does render when i explicitly call EditorFor(x => x.Title)
so I know that I don't have referral problems.
Why is my editor template ignored when I invoke EditorForModel
(or its equivalent EditorFor(x => x)
)
Updates
I created a new project to reproduce this behavior. I just used the default ASP.NET MVC 3 Internet Application.
Index.cshtml
@model MvcApplication1.Models.Region
@{
ViewBag.Title = "Home Page";
}
<h2>@ViewBag.Message</h2>
<p>
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
</p>
@Html.EditorForModel()
HomeController.cs
using System.Web.Mvc;
using MvcApplication1.Models;
namespace MvcApplication1.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View(new Region());
}
}
}
Region.cs
namespace MvcApplication1.Models
{
public class Region
{
public Region()
{
this.Name = "RegionInstance";
this.Title = new LocalizedString();
}
public string Name { get; set; }
public LocalizedString Title { get; set; }
}
}
LocalizedString.cs
namespace MvcApplication1.Models
{
public class LocalizedString
{
public LocalizedString()
{
this.Name = "LocalizedStringInstance";
}
public string Name { get; set; }
}
}
If you run this program, the output will only display a text input for the name of the region. The LocalizedString.cshtml content is never output.
I also tried to use UIHint
over the Region.Title
property, but it still does not display.