asp.net routing cannot find method -
asp.net routing cannot find method -
i have folder crated in application called admin within controllers, folder construction looks this
-models | -views | -controller | |-homecontroller.cs | |-admin | |-homecontroller.cs <-- in controller, have methods add,delete,view
i needed created route if type url http://localhost:2336/admin/add
, execute add together method of home controller, 404 error.
public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.maproute( name: "admin", url: "admin/{controller}/{action}/{id}", defaults: new { controller = "home", action = "index", id = urlparameter.optional }, namespaces: new[] { "fms.controllers.admin" } ); routes.maproute( "default", // route name "{controller}/{action}/{id}", // url parameters new { controller = "home", action = "index", id = urlparameter.optional } // parameter defaults ); }
your admin route specifies route this:
admin/{controller}/{action}/{id}
this means in url need have controller name action. example, should work:
http://localhost:2336/admin/home/add
if alter url route work:
admin/{action}/{id}
however, mean it's little pointless have admin controller in it's own folder. if i'd how create new mvc area.
asp.net-mvc asp.net-mvc-routing
Comments
Post a Comment