代码之家  ›  专栏  ›  技术社区  ›  Steve Horn

在控制器中使用表达式生成链接

  •  0
  • Steve Horn  · 技术社区  · 15 年前

    我希望能够在我的控制器内建立到控制器操作的链接。我真的想做一些事情,比如:

    <%= Html.BuildUrlFromExpression<Controller>(x => x.ActionName(param)) %>
    

    …除了控制器。

    有办法吗?

    2 回复  |  直到 15 年前
        1
  •  0
  •   womp    15 年前

    你可以使用HtmlHelper方法。这就是框架内部使用的东西。

    string myLinkText = HtmlHelper.GenerateLink(
      new RequestContext(this.HttpContext, this.RouteData), 
      RouteTable.Routes,
      "MyLinkText", 
      "RouteName", 
      "ActionName", 
      "ControllerName", 
      this.RouteData.Values,
      new Dictionary<string, object>() {/* attributes here */}
    );
    
        2
  •  0
  •   T W    15 年前