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 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
Usersand a controller forGroups.In the
Userscontroller you will have aactioncalled index which will give you the/Users/Indexview.In the
Groupscontroller you will have anactioncalled index and an action calledAccountYou then can access these via/Groups/Indexand /Groups/Account`.If you wanted to have more nesting then you can use
Areas. AnAreawill allow you to have a full set of controllers for a “sub folder”. For example you can create aareacalled 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/Accountwhere group is the area and account is a controller in that area.