Followed by this post on creating culture and adding prefix culture parameter in all url as follows
ASP.NET MVC 5 culture in route and url
I'm working on magazine (Arabic and English) and links for homepage as follows: localhost:1025/Blog/Home //Default Arabic localhost:1025/en/blog/home // for English
I added new action under Controller 'blog' called 'tag' to show posts for specific tag . already added in routeConfig code as this:
routes.MapRoute(
name: "BlogListTag",
url: "{controller}/{action}/{Name}/{page}/{pageNo}",
defaults: new { controller = "Blog", action = "Tag", Name = UrlParameter.Optional, pageNo = UrlParameter.Optional, page = UrlParameter.Optional }
);
So this must be prefixed by culture constraint parameter as the code applies that:
routes.LowercaseUrls = true;
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Call to register your localized and default attribute routes
routes.MapLocalizedMvcAttributeRoutes(
urlPrefix: "{culture}/",
defaults: new { culture = "ar" },
constraints: new { culture = new CultureConstraint(defaultCulture: "ar", pattern: "[a-z]{2}") }
);
Now on Home action I'm listing articles links in Partial view So Each article has a couple of links for tag page. I used in partial view this code
@Html.ActionLink(@t.Name,"Tag",new { Name = t.NameEn.AddDashes() },new { title= Resources.Resource.Tag+":"+ @t.Name })
When I browse in arabic i get the link when i inspect in browser as this:
localhost:1025/blog/tag?Name=XYZ //in Arabic
When I switch to home page in english
localhost:1025/en/blog/tag?Name=XYZ //in English
it works fine and it catches the culture and include in links . But I don't want to show links with querystrings
here is the issue , when I replace the code by using Html.RouteLink instead of ActionLink , it follows the route from RouteConfig but doesn't take any prefix culture . so here is the link code line :
@Html.RouteLink(@t.Name, "BlogListTag",
new { Name = t.NameEn.AddDashes(),action="tag" },
new { title= Resources.Resource.Tag+":"+ @t.Name })
//Note: I included action because it doesn't work without it
the result link in both arabic and english page
localhost:1025/blog/tag/XYZ //in Arabic
localhost:1025/blog/tag/XYZ //in English 'Note: no culture prefix caught
My final try was to include culture as parameter like this only when culture is En
@Html.RouteLink(@t.Name, "BlogListTag",
new { Name = t.NameEn.AddDashes(),action="tag",culture="en" },
new { title= Resources.Resource.Tag+":"+ @t.Name })
//Note: I included action because it doesn't work without it
//Note: this is only inside the if statement to check the culture as English
and it results the link in English page like this:
localhost:1025/blog/tag/XYZ?culture=en //in English 'Note: QueryString
All I wanted is to be like these:
localhost:1025/blog/tag/XYZ //in Arabic 'this works already in arabic
localhost:1025/en/blog/tag/XYZ //in English
All I want is that RouteLink to work by catching the prefix culture in arabic and English without any attempt to include culture as parameter and without seeing any query strings in the links
Appreciate your reply