1

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.