Reputation: 141
I am using
'routes.MapRoute'
to take one parameter without calling the action name. it works fine, but now my problem is whenever I wanted to use any other action form the same controller it's always calling the same action that is described on the 'routes.MapRoute'.
My ajax calling for all other action has GET type. but still, it's calling the same action that is described in the routes.MapRoute.
//This is my custom route.
routes.MapRoute(
"kuenstler",
"kuenstler/{name}",
new { controller = "kuenstler", action = "Index" }
);
//my default route
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Site", action = "Index", id
=
UrlParameter.Optional }
);
The first route will be called from a link attribute from another page so I need to get the name from there but without the action name.
<a href="kuenstler/name-lastname">link</a>
action that needs to get the name from the calling.
public ActionResult Index(string name)
{
return View();
}
[HttpGet]
public ActionResult GetKuenstlerGalleryData(int? artistId, string
direction)
{
/// some code
}
Every time I am clicking the link
//localhost:50519/Kuenstler/firstname-lastname.
I am getting the name in my Index. Then I am calling the second action from javascript with GET type. But every time it's coming in the Index with the calling action name as parameter.
Upvotes: 1
Views: 123
Reputation: 582
But every time it's coming in the Index with the calling action name as parameter.
Of course it does, your requests path perfectly fits the kuenstler route template. You can map specific route for GetKuenstlerGalleryData action right before 'kuenstler' one. Ex.
routes.MapRoute(
"kuenstler-gallery-data",
"kuenstler/GetKuenstlerGalleryData",
new { controller = "kuenstler", action = "GetKuenstlerGalleryData" }
);
routes.MapRoute(
"kuenstler",
"kuenstler/{name}",
new { controller = "kuenstler", action = "Index" }
);
or use separate template, ex.
routes.MapRoute(
"kuenstler-gallery-data",
"kuenstler-gallery-data",
new { controller = "kuenstler", action = "GetKuenstlerGalleryData" }
);
or even use attribute routing
Upvotes: 1