SeToY
SeToY

Reputation: 5895

Subfolders for MVC Views

My regular url layout looks like this:

http://localhost:1337/Site1

http://localhost:1337/Site2

http://localhost:1337/Site3

Now I want to create the administration in a separate sub-folder in the /Views/ directory. So the URLs should look like:

http://localhost:1337/Administration/AdminSite1 http://localhost:1337/Administration/AdminSite2 http://localhost:1337/Administration/AdminSite3

This apparently doesn't work with just creating a subfolder in the Views directory.

This is what my views folder looks like:

/Views/Site1/Index.cshtml

/Views/Site2/Index.cshtml

/Views/Site3/Index.cshtml

/Views/Administration/AdminSite1/Index.cshtml

/Views/Administration/AdminSite2/Index.cshtml

/Views/Administration/AdminSite3/Index.cshtml

And the controllers folder accordingly:

/Controllers/Site1Controller/

/Controllers/Site2Controller/

/Controllers/Site3Controller/

/Controllers/Administration/AdminSite1Controller/

/Controllers/Administration/AdminSite2Controller/

/Controllers/Administration/AdminSite3Controller/

How can I handle this?

Upvotes: 1

Views: 6448

Answers (1)

haim770
haim770

Reputation: 49095

What's you're actually looking for is Areas (an ASP.NET MVC term, sometimes referred to as 'Module' in other MVC frameworks).

See here: http://msdn.microsoft.com/en-us/library/ee671793(v=vs.100).aspx

In short, an Area will let you have controllers & views specific to the 'Area', like so:

Regular structure (default area):

/Models
/Controllers
/Views/[Controller]/[Action].cshtml

'Admin' area (for example):

/Areas/Admin/Models
/Areas/Admin/Controllers/
/Areas/Admin/Views/[Controller]/[Action].cshtml

As of routing, you'll usually have to configure it manually by 'registering' areas in Global.asax.

Upvotes: 2

Related Questions