문제

My question is about the process of designing an ASP.NET MVC site and specifically about determining what controller classes and action Methods my site should have.

This is what I understand so far about the process of designing an ASP.NET MVC web site:

  1. First, I should use a mock-up tool such as Balsamiq to create a mock-up, so I know how my site should look. This gives me the views.
  2. Second (or concurrently), I model the objects of my domain.

Given the views and the model, how do I proceed with the controller classes and their action Methods? A controller can call different views, so what's my "factoring" criteria?

So, my question is: Given the views and the model, how do I decide what controllers to have and which action methods each should contain?

도움이 되었습니까?

해결책

Imho, a controller should reflect a specific functional area, dealing with a group of features related to each other. For example, you can have a controller dedicated to user management, where you create and edit users, manage user rights, user profiles, anything related to your users, another controller for product management, where you display available products according to user inputs, manage stocks, suppliers, and such...

With too much controller you end up redirecting all day long, with too few controller it's a mess to maintain.

Of course, when i say"this controller manages that group of features", i don't say "put all your business logic here". Controller's duty is to call the right business method(s) and to pass this data to the right view.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top