如何将参数添加到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>

谢谢你!

您应该将它们全部放在对象参数中。

https://learn.microsoft.com/en-us/dotnet/api/system.web.mvc.urlhelper.action?view=aspnet-mvc-5.2#System_Web_mvc_UrlHelper_Action_System_String_System_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" })

最新更新