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

How to add parameters to 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://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" })