What is the best way to separate MVC controller functions?

When creating controllers, what are the best ways to share it?

If I have an administration section that has a .ascx web user group, under it and several .aspx pages. Should I have one AdminController? Or should I have a controller for each individual control / web user?

It seems that responsibility for the actions of one page goes against one of the things that MVC tried to improve from Web Forms. But at the same time, you do not need one controller for your entire website ...

I understand what controllers should do, but how much should one separate controller respond? What are the best practices for sharing responsibility between controllers?

Thanks
Matt

+3
source share
2 answers

The full answer is 75%, but as a very flexible answer, one controller per model, and then just gives it enough flexibility to create, read, update and delete this model (it is desirable that the interface be consistent between the controllers and avoid the special case of interfaces, if this is absolutely necessary.)

This works for all cases, except for those for which it is not!

REST is a pretty good basis for thinking about this. Although the following guide focuses on how this is done by rails, many concepts should be applied more widely http://www.softiesonrails.com/2007/3/28/rest-101-part-1-understanding-resources

+2

AdminController - . , , .

Nerddinner.

0

Source: https://habr.com/ru/post/1710999/


All Articles