I have my routes configured like this in my global.asax
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"poems-by-profile", // Route name
"profile/{id}/{name}/poems", // URL with parameters
new { controller = "poems", action = "Index", id = "", name = "" } // Parameter defaults
);
routes.MapRoute(
"profile", // Route name
"profile/{id}/{name}", // URL with parameters
new { controller = "profile", action = "Index", id = "", name = "" } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}/{name}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional, name = UrlParameter.Optional } // Parameter defaults
);
Here are my two controllers
public class ProfileController : BaseController
{
public ActionResult Index(int id, string name)
{
return View();
}
}
public class PoemsController : BaseController
{
public ActionResult Index(int id, string name)
{
return View();
}
}
Somewhere on home page, I have html action link like this
@Html.ActionLink("Profile", "index", "Profile", new { id = 1, name = "someuser" })
@Html.ActionLink("Poems by ", "index", "poems", new { id = 1, name = "someuser" })
I am expecting two urls like
http://localhost/profile/1/someuser
http://localhost/profile/1/someuser/poems
But it is not creating these urls.
Am I doing something wrong.
Help will be appreciated.
//Updating my question here
Actually this one works
@Html.ActionLink("Profile", "index", "Profile", new { id = 1, name = "someuser" },null)
@Html.ActionLink("Poems by ", "index", "poems", new { id = 1, name = "some user" },null)
Passing null as last parameter.
Dont know why, but it works.
Cheers
Parminder