How to add parameters to url.action()?

573 views Asked by At

I am trying to add some parameters like rel and hreflang to my language selection links, but it seems that there is a limited number of parameters.

Is there any other solution to do that ? I know it's feasible with actionLink, but url.action seems to be easier for links on images...

 <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>

Thannk you !

1

There are 1 answers

0
Jerdine Sabio On BEST ANSWER

You should put them all inside the object parameter.

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_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" })