I have the following custom route
routes.MapRoute("custom", "Groups/{groupname}/{action}/{id}", new { controller = "Groups", action = "Index", id = UrlParameter.Optional });
This custom route is to achieve the following url schema
I tried the following but it doesnt work. it confuses asp .net mvc of which action to select.
public ActionResult Members(string groupName, string id)
{
return View();
}
public ActionResult Members(string groupName)
{
return View();
}
There are two possible solutions that i could think of:
I very much want to maintain my url scheme. thus, as per my original question, how to have two different views associated to one action? Thanks.
RWendi
You can only have one action, but you can perform whatever logic you want inside that action, and you can call views by name:
return View("MyView");
In your example, you would simply return a different view if the id field was null.
where it says return View(); It takes parameters and you can get it to use whatever view you would like
return View("Members", model);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With