如何向url.action()添加参数?

时间:2020-03-29 08:56:14

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

我正在尝试向我的语言选择链接中添加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>

谢谢!

1 个答案:

答案 0 :(得分:1)

您应该将它们全部放入object参数中。

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" })
相关问题