I have the following classes:
public class Widget
{
public string Name { get; set; }
}
GenericModel
public class GenericModel<T>
{
public List<T> Data { get; set; }
}
My Controller action is:
public ActionResult Simple()
{
var model = new GenericModel<Widget>()
{
Data = new List<Widget>
{
new Widget {Name = "a"}
}
};
return View(model);
}
And my view is:
@model MyApp.GenericModel<MyApp.Widget>
@{
ViewBag.Title = "Simple";
}
<h2>Simple</h2>
@Html.DisplayFor(m=>m)
I have a file called GenericModel.cshtml in Views/Shared/DisplayTemplate folder:
@model MyApp.GenericModel<MyApp.Widget>
<ul>
@for (int i = 0; i < Model.Data.Count; i++ )
{
<li>
@Html.EditorFor(m=> Model.Data[i].Name)
</li>
}
</ul>
This view can not be found. I see when I print out the name of the type of my model I get "GenericModel1". Seeing that, I renamed my template "GenericModel
1.cshtml". This seems like a bit of a hack, is there an easier way to find this display template without resorting to this?