2

I've got a View rendering an EditorFor of an AgreementSearch object, which in turn has an EditorFor of a BaseEmployeeSearch object since AgreementSearch inherits from BaseEmployeeSearch. The issue is that the EditorFor the BaseEmployeeSearch object has returns with nothing in it.

When used separately the BaseEmployeeSearch objects EditorTemplate works just fine, and if the issue were because of a misname or something I would expect the object's .ToString editor to come up by default.

Could someone shed some light on this?

AgreementSearch Edit Template:

@model TimecardRepository.Models.AgreementsModels.BusinessObject.AgreementSearch

@Html.EditorForModel("_BaseEmployeeSearch")

<h4>HEY THERE!</h4>

<span class="margin_left_2em">
@Html.LabelFor(x => x.AgreementStatus, "Filter by agreement Type: ")
@Html.DropDownListFor(x => x.AgreementStatus, new SelectList(new[] 
            { 
                new { desc = "All agreement types", value = "0" }, 
                new { desc = "Disagreements Only", value = "1" }, 
                new { desc = "Agreements Only", value = "2" }, 
                new { desc = "Awaiting Agreement", value = "3" }  
            }, "value", "desc", (Model != null) ? Model.AgreementStatus : 0))
</span>

<span class="margin_left_2em">
@Html.LabelFor(x => x.AgreementStatus, "Filter by last comment: ")
@Html.DropDownListFor(x => x.AgreementStatus, new SelectList(new[] 
            { 
                new { desc = "All comment types", value = "0" }, 
                new { desc = "No comments", value = "1" }, 
                new { desc = "Last comment from Payroll", value = "2" },
                new { desc = "Last comment from Field", value = "3" }  
            }, "value", "desc", (Model != null) ? Model.CommentStatus : 0))
</span>

BaseEmployeeSearch Edit Template

@model TimecardRepository.Models.Shared.BaseEmployeeSearch

<span>
@Html.LabelFor(model => Model.FirstName, "First: ")
@Html.TextBoxFor(model => Model.FirstName, new { style = "width: 7em;", maxlength = "12" })
</span>
<span class="margin_left_2em">
@Html.LabelFor(model => Model.LastName, "Last: ")
@Html.TextBoxFor(model => Model.LastName, new { style = "width: 7em;", maxlength = "12" })
</span>
<span class="margin_left_2em">
@Html.LabelFor(model => Model.MemberID, "SMID: ")
@Html.TextBoxFor(model => Model.MemberID, new { style = "width: 6em;", maxlength = "7" })
</span>
<span class="margin_left_2em">
@Html.LabelFor(model => Model.Entity, "Entity: ")
@Html.TextBoxFor(model => Model.Entity, new { style = "width: 5em;", maxlength = "6" })
</span>
<span class="margin_left_2em">
@Html.LabelFor(model => Model.PayPeriod.Offset, "Pay Period: ")
@Html.DropDownListFor(model => Model.PayPeriod.Offset, new SelectList(new[] { new { desc = "Current", value = "0" }, new { desc = "Next", value = "1" }, new { desc = "Previous", value = "-1" } }, "value", "desc"))

@Html.HiddenFor(model => Model.PayPeriod.StartDate)
@Html.HiddenFor(model => Model.PayPeriod.EndDate)
</span>    
  • WOW - you have a lot of @Html.___for that you are doing nothing with but creating HTML - i.e. @Html.DropDownListFor(x => x.AgreementStatus... - how about just writing some simple HTML? Start with the rendered markup and see what your actual form looks like and does it match the model you are posting to? – viperguynaz Apr 17 '13 at 02:54
  • Yes I do have a lot of Html helpers, I did try using straight simple Html for the BaseEmployeeSearch but that did not change the issue that I have. Ultimately I'm using the helpers to make my life easier by implementing partial views (through editor templates) and cant get the Html.EditorFor() to work correctly in this instance. – Lawrence Stone May 02 '13 at 18:35
  • I am facing the same problem. Did you find a fix for it? – Christoph Fink Apr 27 '14 at 13:32
  • Trust me, I feel your pain: https://stackoverflow.com/questions/6811717/in-an-editor-template-call-another-editor-template-with-the-same-model – Steven Twors Nov 17 '18 at 06:58

0 Answers0