I have a controller named Raportare that has two actions: ReportA and ReportB.
Both return an excel file based on the parameters supplied.
public ActionResult ReportA(int? month, int? year)
{
...
}
public ActionResult ReportB(int? month, int? year)
{
...
}
My global.asax has the following routing rules for this :
routes.MapRoute(
"ReportA",
"{Raportare}/{ReportA}/{month}/{year}",
new { controller = "Raportare", action = "ReportA", month = UrlParameter.Optional, year = UrlParameter.Optional});
routes.MapRoute(
"ReportB",
"{Raportare}/{ReportB}/{month}/{year}",
new { controller = "Raportare", action = "ReportB", month = UrlParameter.Optional, year = UrlParameter.Optional });
However when I go mysite.com/Raportare/ReportB/5/2012 it’s returning the ReportA file.
It works fine if I go to mysite.com/Raportare/ReportB?month=5&year=2012.
Probably I’m doing something wrong in the routing rules but I can’t figure it out.
You don’t need to add a route for every action – they work like templates and the 3rd parameter is just default values.
Put this before your default rule in Global.asax.cs, otherwise the default might match first.
Then
mysite.com/Raportare/ReportB/5/2012will invoke theReportBaction because it has been specified in the url.mysite.com/Raportarewill invokeReportA, because it is the default action.