how can i add two page route in mvc?
-
hi all i want use page mappageroutr in simple mvc project but i cant; my code is:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); routes.MapRoute( "viewstudent", // Route name "view/viewstudent", // URL with parameters new { controller = "Movie", action = "Select", id = UrlParameter.Optional } // Parameter defaults ) ; }
if i comment route "viewstudent" or comment route 'Default' my route is correct and work but two routmap with together dosent work! thanks for any help
-
hi all i want use page mappageroutr in simple mvc project but i cant; my code is:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); routes.MapRoute( "viewstudent", // Route name "view/viewstudent", // URL with parameters new { controller = "Movie", action = "Select", id = UrlParameter.Optional } // Parameter defaults ) ; }
if i comment route "viewstudent" or comment route 'Default' my route is correct and work but two routmap with together dosent work! thanks for any help
Hello. Order of routes matters in MVC so in example above the default route will always hit for viewsudent. Swap them and it should work. Take also a loot at this blog post[^] for debugging MVC routes.
-- "My software never has bugs. It just develops random features."
-
Hello. Order of routes matters in MVC so in example above the default route will always hit for viewsudent. Swap them and it should work. Take also a loot at this blog post[^] for debugging MVC routes.
-- "My software never has bugs. It just develops random features."
-
hi all i want use page mappageroutr in simple mvc project but i cant; my code is:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); routes.MapRoute( "viewstudent", // Route name "view/viewstudent", // URL with parameters new { controller = "Movie", action = "Select", id = UrlParameter.Optional } // Parameter defaults ) ; }
if i comment route "viewstudent" or comment route 'Default' my route is correct and work but two routmap with together dosent work! thanks for any help
The "Default" route map should always be placed at the end. Try swapping the two MapRoute and it will work.