i quite new mvc. facing problem routing right now. project url /account/create. can access controller , stuff create, need access /account controller because need write code in level.
/account/create - can access code level
/account - dont know how access controller
project stucture:
sample project
- controler
- model
- view
what supposed change in following code?
//global.asax.cs public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.maproute( "default", // route name "{controller}/{action}/{id}", // url parameters new { controller = "home", action = "index", id = urlparameter.optional } //parameter defaults ); }
/account/create
accessing code in account controller. create
has method on account controller (unless modify default routes). public method define on account controller accessible via /account/method
url. based on route posted, going /account url going call account controller index method:
routes.maproute( "default", // route name "{controller}/{action}/{id}", // url parameters **new { controller = "home", action = "index", id = urlparameter.optional }** // parameter defaults );
that action = "index" part above defining default method on account controller is, going /account url equivalent in case /account/index url
and noticed spelled account wrong in question, not sure if may issue ;)
update
not sure if you're after, if need write code @ /account level can in constructor of controller.
Comments
Post a Comment