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

urlhelper.action:希望生成以“something”结尾的链接

  •  4
  • Liz  · 技术社区  · 14 年前

    我正在尝试创建一个链接 URL动作 ,结尾是 某物 我想路由值中有一些东西可以正确地完成这项工作,但是我在Google中找不到它。

    到目前为止,我试过了 Url.Action("action", "controller", new {id="something", Area="area"}) . 结果链接是预期的/动作/控制器/区域,但我不能在结尾处附加一些内容。

    从网址上看,我可能会说 <a href="<%= Url.Action(..) %>#something"> 但这并没有让我觉得特别好,我正在寻找更好的解决方案。

    2 回复  |  直到 10 年前
        1
  •  12
  •   Mattias Jakobsson    14 年前

    Url.Action()

    public static MvcHtmlString Action(this UrlHelper urlHelper, string action, string controller, string hash)
    {
        return string.Format("{0}#{1}", urlHelper.Action(action, controller), hash);
    }
    
    推荐文章