ASP.NET MVC Subcontrollers
How can i create a sub-controller in ASP.NET MVC? i.e:
In controller's directory i have a controller named Users.Fine.//GET:/Users/Index
Inside controlles folder i have a subfolder named Groups,inside that subfolder i have a directory name Account,and inside Account i have a controller named Group.
So,the URL 开发者_JAVA技巧should be: GET:/Groups/Account/Index
Correct? But it doenst work,cant find that URL. It expects:GET:Groups/Index
Any ideias?
You should not have subfolders in a controller. You should have a Controller for Users
and a controller for Groups
.
In the Users
controller you will have a action
called index which will give you the /Users/Index
view.
In the Groups
controller you will have an action
called index and an action called Account
You then can access these via /Groups/Index
and /Groups/Account`.
If you wanted to have more nesting then you can use Areas
. An Area
will allow you to have a full set of controllers for a "sub folder". For example you can create a area
called Group. Then you will have a default "Home" controller and view which would act as the index and you could add new controllers and views for each "sub-subpage" i.e /Groups/Account
where group is the area and account is a controller in that area.
精彩评论