With the following code in controller, I can pass the value of genre as “rock” with this url: “http://localhost:2414/Store/Browse?genre=rock”
public string Browse(string genre)
{
string message = HttpUtility.HtmlEncode("Store.Browse, Genre = "
+ genre);
return message;
}
I want to pass the same value of genre when the URL is “http://localhost:2414/Store/Browse/rock”
How can I do that?
First of all your controller action shouldn’t look as it currently does. All controller actions should return an ActionResult and you shouldn’t be HTML encoding parameters inside. That’s the responsibility of the view:
and then in your view display and HTML encode like this:
Now back to your question about handling urls like this. You could simply define the following route in your
Global.asax:and then
http://localhost:2414/Store/Browse/rockwill invoke theBrowseaction on theStorecontroller passingrockasgenreparameter.