除非您修改视图模型并让控制器传递必要的信息,否则您不能以强类型的方式执行此操作。所以
public class MyModelTypeWithDelegate
{
public MyModelType MyModelType { get; set; }
public TheDelegate MyModelTypeDelegate { get; set; }
}
public class MyViewModel
{
public MyModelTypeWithDelegate MyModelTypeWithDelegate { get; set; }
}
接着:
<%= Html.EditorFor(m => m.MyModelTypeWithDelegate, "ThatEditor") %>
另一种可能性是将其作为附加视图数据传递,但不会是强类型:
<%= Html.EditorFor(m => m.MyModelTypeField, "ThatEditor", new { TheDelegate = someDelegate }) %>
然后在您的编辑器模板中:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyModelType>" %>
<%
var del = (TheDelegate)ViewData["TheDelegate"];
%>