I have Get actions in my controllers which have two parameters. I call them from Razor views like this using JS functions:
function deleteAddress(addressId) {
url = '@Url.Action("Delete", "Addresses",new { addressId = "3",actionRouteAfterActionFinish="SelectAddress"})';
openLink(url);
}
And here is declaration of my action inside controller:
public async Task<ActionResult> Delete(int addressId,string actionRouteAfterActionFinish){
...
...
}
When I add below Attribute route it works well and both paramters are passed correctly from Razor view to Delete
action:
[Route("Addresses/Delete/{addressId}/{actionRouteAfterActionFinish}")]
But when I try to use below RouteConfig
it does not work and 2nd parameter is set null
when method is get called from Razor view. I wonder how can I rewrite RouteConfig
to manage actions with two parameters?
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//enabling attribute routing
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Intro", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "TwoParamterAction",
url: "{controller}/{action}/{parameter1}/{paramter2}"
);
I reordered Default
rule with TwoParamterAction
rule but it did not help.