【问题标题】:How to add parameters to url.action()?如何向 url.action() 添加参数?
【发布时间】:2020-07-09 17:26:53
【问题描述】:

我正在尝试在我的语言选择链接中添加一些参数,例如 rel 和 hreflang,但似乎参数数量有限。

还有其他解决方案吗?我知道使用 actionLink 是可行的,但 url.action 似乎更容易用于图像上的链接......

 <li><a href="@Url.Action(ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["controller"].ToString(), new { culture = "en" }, null, new { rel = "alternate" }, new { hreflang = "en" })"><img class="language-flag" src="~/Content/images/flags/en.png" height="15" width="15" />@MyWebsite.Resources.Language.English</a></li>

谢谢!

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-4 url-action


    【解决方案1】:

    你应该把它们都放在对象参数中。

    https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.urlhelper.action?view=aspnet-mvc-5.2#System_Web_Mvc_UrlHelper_Action_System_String_System_String_System_Object_

    Url.Action(ActionString, ControllerString, Object)

    @Url.Action(ViewContext.RouteData.Values["action"].ToString(),ViewContext.RouteData.Values["controller"].ToString(), new { @culture = "en", @rel = "alternate", hreflang = "en" })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-01
      • 2014-04-01
      • 2014-08-07
      • 2021-07-22
      • 1970-01-01
      相关资源
      最近更新 更多