代码之家  ›  专栏  ›  技术社区  ›  mxmissile

如何将表达式指定给模型属性,然后在ActionLInk的分部中使用它?

  •  0
  • mxmissile  · 技术社区  · 16 年前

    是否可以将Lambda表达式(操作?)指定给我的视图模型的属性,然后在局部视图中使用该表达式?模型的属性类型应该是什么?Psuedo代码:

    public class MyModel
    {
        public ????? MyAction {get;set;}
    }
    

    public ActionResult Index()
    {
       var model = new MyModel();
       model.MyAction = ?????<MyController>(x => x.DoThis());
    
       return View(model);
    }
    
    public ActionResult DoThis()
    {
       return View();
    }
    

    部分ascx

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyModel>" %>
    
    <%=Html.ActionLink<Controller>(x => x.DoThis())%>
    

    我正在使用Futures程序集中的强类型ActionLink。

    1 回复  |  直到 16 年前
        1
  •  0
  •   tvanfosson    16 年前

    试试这个:

    public class MyModel
    {
        Expression<Action<MyController>> Action { get; set; }
    }
    
    ...
    
    model.Action = x => x.DoThis();
    
    ...
    
    <%= Html.ActionLink( Model.Action ) %>