I have a strongly typed view in which the first line is;
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Employee.Master"
Inherits="System.Web.Mvc.ViewPage<IEnumerable<SHP.Models.AnnualLeaveBooked>>" %>
To avoid Id collisions I want to display the collection in a grid so I use an editor template (one of the fields gets edited).
So in my code I put in the line;
<%: Html.EditorFor(x => x) %>
And then in the EditorTemplate sub folder I put in this template;
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SHP.Models.AnnualLeaveBooked>" %>
<tr>
<td>
<%: String.Format("{0:g}", Model.AnnualLeaveDate) %>
</td>
<td>
<%: Model.ApprovedStatus %>
</td>
<td>
<%: Html.CheckBoxFor(model => model.CancelFlag) %>
<%: Html.HiddenFor(model => model.AnnualLeaveBookedId) %>
</td>
</tr>
The problem I am having is that the EditorFor command does not seem to recognise the EditorTemplate.
What am I doing wrong?
Incidently I would be suprised if x => x is wrong, there is probably a better way to express this.
Your editor template should be:
~/Views/Home/EditorTemplates/AnnualLeaveBooked.ascxwhereHomeis the name of the controller. If it is a global editor template you could also put it in~/Views/Shared/EditorTemplates/AnnualLeaveBooked.ascx. Notice the name of the editor template: it should be the same as your type name (AnnualLeaveBooked.ascx).Also instead of:
you could:
Finally if you want to name your editor template with some custom name like
~/Views/Home/EditorTemplates/Foo.ascxyou could specify this custom name: