我有一个强类型的Person视图,我想渲染一个部分:
人物视图(强类型为人物)
<label for="name">Name</label>
<% Html.RenderPartial("AddressForm"); %>
</label>
Run Code Online (Sandbox Code Playgroud)
AddressForm View(无类型,因为我也想在分发器强类型视图中使用它)
当我尝试从Person视图中调用此partial时,我收到此错误:
编译器错误消息:CS1963:表达式树可能不包含动态操作
来源错误:
Line 8: </div>
Line 9: <div class="editor-field">
Line 10: <%= Html.TextBoxFor(model => model.addressLine1) %>
Line 11: <%: Html.ValidationMessageFor(model => model.addressLine1) %>
Line 12: </div>
Run Code Online (Sandbox Code Playgroud)
如何让这部分渲染,以便我可以在多个其他类型中使用我的部分addressView?
编辑:
// GET: /Person/Create
public ActionResult Create()
{
Person person = new Person();
return View(person);
}
//Person create view
<% Html.RenderPartial("AddressForm"); %>
//AddressForm Partial
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<fieldset>
<legend>Address</legend>
<div class="editor-label">
<label for="addressLine1" class="addressLabel">Address Line 1</label>
</div>
<div class="editor-field">
<%= …Run Code Online (Sandbox Code Playgroud)