请帮忙!这让我疯狂。Html.Edit For not finding editor template
我试图重构一些代码,因为在模型,视图和控制器中有一堆剪切和粘贴。
视图模型
namespace Foo.Models.Bar
{
[KnownType(typeof(RecruitEditModel))]
public class RecruitEditModel
{
//...
public CommonServicesEditModel Services { get; set; }
服务是包含在那里我把通用代码模型中的另一个类的属性。
查看Foo中的\ Views
@model RecruitEditModel
@* ... *@
@using (Html.BeginForm("RecruitEdit", "AppMgmt", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@* ... *@
@*@Html.Partial("TradeEdit", Model.Services) <<< DOESN'T BIND *@
@Html.EditorFor(m => m.Services) @* BINDS *@
<input type="submit" value="Save" />
}
使用部分在嵌套类将无法工作,因为嵌套类将不绑定。 (http://lostechies.com/jimmybogard/2011/09/07/building-forms-for-deep-view-model-graphs-in-asp-net-mvc/)
所以我必须使用一个编辑器模板。
编辑模板Foo中的\ Views \共享\ EditorTemplates \ TradeEdit.cshtml
@model Services.CommonServicesEditModel
<div class="left">
<h3>Howdy</h3>
<div class="left theTrade">General Contracting: </div>
@Html.EditorFor(model => model.TradeGC)
@Html.ValidationMessageFor(model => model.TradeGC)
</div>
@*...*@
我遇到的问题是显然的编辑模板没有被发现,而不是默认的编辑器正在生成。
我在试图调整CSS时发现了这一点。没有生成EditorTemplate标题中的“Howdy”。不管我做什么,在评论EditFor调用时都没有改变显示的字段。
我在本地IIS上运行调试,我试过重新启动应用程序池和刷新网站,但没有喜悦。
如何在编辑器模板中获取更改以传播到视图?
你这里真的搞砸了......你的语境没有道理...... TradeGC是什么类型的?你的文章说这个模板叫做TradeEdit.cshtml,是不是叫了?我没有在那里看到一个TradeEdit类型..你的类型与你展示的类型完全不同......我也没有在这里看到任何嵌套类...服务不是嵌套类,它只是一个属性。嵌套类是* DEFINED *在其他类中的类...即'class foo {class bar {...}}' – 2014-10-31 20:50:46