Today I try to use route name in my MVC
string url = urlHelper.RouteUrl(routeName, routeValues);
Yes it don't work because it didn't find my route name
A route named 'Index' could not be found in the route collection.
Only route name "Default" i can use so what the point?
to use route name work you must map like
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Vsaving", action = "Index", id = "" } // Parameter defaults
in Global.aspx ( I still don't test this )
another way use Action instead Route like this
RedirectToAction(string actionName, string controllerName);
compare with
RedirectToRoute(string routeName); If want to go "Index2" or something you must routes.MapRoute before
This is clear?
ไม่มีความคิดเห็น:
แสดงความคิดเห็น