When should I create new Controller class in Asp.net MVC (Design Question)?

后端 未结 2 1380
星月不相逢
星月不相逢 2021-01-14 18:18

Before I ask the question, here is my understanding about Controller in MVC pattern.

  1. Controller is Application Layer (in DDD)
  2. It controls Application
相关标签:
2条回答
  • 2021-01-14 18:44

    Common practice is to create a controller associated with each view. When the application is using Restful URL design, this usually maps to the index, new, edit and delete actions. You can then map an method to handle each action.

    http://example.com/examples/1/edit - maps to edit method on ExamplesController
    http://example.com/examples/1/new - maps to new method on ExamplesController
    http://example.com/examples - maps to index method on ExamplesController
    http://example.com/examples/1/delete - maps to delete method on ExamplesController
    
    http://example.com/users/1/edit - maps to edit method on UsersController
    http://example.com/users/1/new - maps to new method on UsersController
    http://example.com/users - maps to index method on UsersController
    http://example.com/users/1/delete - maps to delete method on UsersController
    
    0 讨论(0)
  • 2021-01-14 18:53

    After working on ASP.net MVC and rails, I think Controller should create per Resource (in the REST style application).

    0 讨论(0)
提交回复
热议问题