Dis*_*ile 15 .net asp.net-mvc mvc-editor-templates asp.net-mvc-3
我想从我的控制器返回一个EditorTemplate作为Partial View.
我目前在做:
public ActionResult Create([Bind(Prefix="Create")]CreateViewModel model)
{
return PartialView("~/Views/Shared/EditorTemplates/Template.cshtml", model);
}
Run Code Online (Sandbox Code Playgroud)
问题是,在我这样做之后,Create_前缀远离我的观点.有没有办法将编辑器模板作为局部视图返回并保留前缀?
Index.cshtml @model IndexViewModel
@using(Html.BeginForm("Create"))
{
@Html.EditorFor(m => m.Create, "Template")
<input type="submit" value="Save" />
}
Run Code Online (Sandbox Code Playgroud)
我正在通过AJAX调用提交此表单.当我最初调用EditorFor时,所有字段都有一个前缀Create_.但是,在我提交表单并返回此PartialView后,前缀将丢失.
Dar*_*rov 26
由于模板未在主视图的上下文中调用,因此会丢失其上下文.您可以在这种情况下定义前缀,如下所示:
public ActionResult Create([Bind(Prefix="Create")]CreateViewModel model)
{
ViewData.TemplateInfo.HtmlFieldPrefix = "Create";
return PartialView("~/Views/Shared/EditorTemplates/Template.cshtml", model);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7154 次 |
| 最近记录: |