EditorFor和Inheritance中的EditorFor

时间:2013-04-16 22:54:02

标签: asp.net-mvc-4

我有一个View渲染一个ProtocolFor对象的EditorFor,而这个对象又有一个BaseFormployeeSearch对象的EditorFor,因为AgreementSearch继承自BaseEmployeeSearch。问题是EditorFor the BaseEmployeeSearch对象返回时没有任何内容。

单独使用BaseEmployeeSearch对象时,EditorTemplate工作得很好,如果问题是由于错误名称或其他原因,我希望对象的.ToString编辑器默认出现。

有人可以对此有所了解吗?

协议搜索编辑模板:

@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编辑模板

@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>    

0 个答案:

没有答案