【问题标题】:How to generate just the URL of the Controller method in ASP.NET MVC如何在 ASP.NET MVC 中仅生成 Controller 方法的 URL
【发布时间】:2011-01-29 22:51:13
【问题描述】:

所以Html.ActionLink("Report", "SendMail", "Misc", new { id = Model.ImageID }, null) 将生成一个格式良好的链接。

<a href="http://localhost:3224/Misc/SendMail/5">Send Mail</a>

如果不解析 Html.ActionLink 的输出,如何只生成链接的 URL?

【问题讨论】:

    标签: asp.net-mvc visual-studio-2008 .net-3.5 html.actionlink


    【解决方案1】:

    这对你有用吗

    <%= Url.Content("~/Misc/SendMail/" + Model.ImageID) %>
    

    或者试试

    <%= Url.Action( "SendMail", "Misc", new { id = Model.ImageID }) %>
    

    【讨论】:

    • 这很好,但该应用程序将在各种 IIS 盒子(一些 v6 和一些 v7)上运行,因此在 IIS6 的情况下它可能是 /Misc.aspx/SendMail。
    • Url.Action 可能是你的朋友。
    • 好的,谢谢。这会生成 /Misc.aspx/SendMail/1,这是完美的。现在我需要它之前的东西。知道如何获取域 + 虚拟目录吗?
    【解决方案2】:
    <%= Url.Content("~"+Url.Action( "SendMail", "Misc", new { id = Model.ImageID })) %>
    

    我认为应该适合你

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-17
      • 1970-01-01
      • 2021-09-08
      相关资源
      最近更新 更多