I'm having an issue with url route with parameter. I followed by this link: ASP.NET MVC 5 culture in route and url
I have tag action under controller Blog. According to culture, I created two routes in route config :
routes.MapRoute(
name: "TagWithCulture",
url: "{culture}/{controller}/{action}/{Name}/{page}/{pageNo}",
defaults: new { controller = "Blog", action = "Tag", Name = UrlParameter.Optional, pageNo = UrlParameter.Optional, page = UrlParameter.Optional },
constraints: new { culture = new CultureConstraint(defaultCulture: "ar", pattern: "[a-z]{2}") }
);
routes.MapRoute(
name: "Tag",
url: "{controller}/{action}/{Name}/{page}/{pageNo}",
defaults: new { controller = "Blog", action = "Tag", Name = UrlParameter.Optional, pageNo = UrlParameter.Optional, page = UrlParameter.Optional }
)
The action in controller is as this line of code to accept 2 parameters:
public async Task<ActionResult> Tag(string Name, int? pageNo)
The problem is: when I browse url with query string like this:
localhost:1025/blog/tag?name=XYZ
and debug, I can see that 'name' parameter has a value, otherwise, by browsing url and applying route:
localhost:1025/blog/tag/XYZ
the parameter 'name' becomes null!
This is causing a headache, is there a solution for that?