Reputation: 89
I'm using MVC 4.
My default route on my site is Home/Index
so when the user enters the URL www.example.com
it goes to that route.
Could you let me know if it is also possible to receive a parameter appended to that URL i.e. www.example.com/param
? It works if I use www.example.com/Home/Index/param
but that's not ideal.
I'm guessing its something I need to add to the Global.asax
but I can't find examples anywhere.
Upvotes: 4
Views: 270
Reputation: 902
context.MapRoute(
"Home_all",
"/{*actions}",
new { controller = "Home", action = "Index"}
);
But be aware that route will match all urls , so you need to register it at last :) That Routing will be called like this in your Home Controller for example... Actions will be a part from the url, and you can even add some parameter in the query string
public ActionResult Index(string actions, string id)
{
}
Upvotes: 3