Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Administration Area in Asp.Net MVC

My question may be obvious but I'd like to build a well-designed web application. As for any administration area, the admin should be able to list/create/delete/modify users, articles, posts, etc...

I'd like to know what is the best way to design the application. Should I create a controller for each one of those items (/Users/Create/id or /Posts/Delete/id), or create all of the action in my Administration Controller (/Administration/CreateUser/id or /Administration/DeletePost/id) ?

like image 762
Flesym Avatar asked May 25 '09 06:05

Flesym


People also ask

What are areas in ASP.NET MVC?

Area allows us to partition the large application into smaller units where each unit contains a separate MVC folder structure, same as the default MVC folder structure. For example, a large enterprise application may have different modules like admin, finance, HR, marketing, etc.

How many types of routing are there in MVC?

MVC 5 supports a new type of routing, called attribute routing. As the name implies, attribute routing uses attributes to define routes. Attribute routing gives you more control over the URIs in your web application. The earlier style of routing, called convention-based routing, is still fully supported.

What is _layout Cshtml in MVC?

The file "_Layout. cshtml" represents the layout of each page in the application. Right-click on the Shared folder in Solution Explorer then go to "Add" item and click on "View". Now the View has been created.


2 Answers

You should write a separate controller for each entity to keep a clean separation of concerns for your controller classes. If you only have one controller, then you will only have one Views directory with dozens of views, and your controller will contain dozens of methods, and that will soon become unmanageable.

like image 100
womp Avatar answered Sep 29 '22 00:09

womp


The answer depends on how much functionality will be in the controllers. Just start of with one controller and if it gets too much split it into a few. The great thing about MVC is where you put things in your controllers doesn't have to have any effect on the URLs. you can very easily map /Users/Create to e.g. UserAdminController class.

like image 41
Jonathan Parker Avatar answered Sep 29 '22 01:09

Jonathan Parker