ASP.NET MVC - A strongly typed view model, where does it belong?

I'm trying to create a strongly typed view model, as John Sheehan suggests here . Where should he go? I can make arguments for myself for Model, View and Controller.

+3
source share
4 answers

It must go into the Models directory of the web application. ViewModels, by definition, refer to one or more views and therefore belong to a web application, not to the kernel.

You can define them in the controller that uses them, but this does not scale. Same thing with class definition in view code. Despite the fact that one class for files means more files, it is easier to find the code and simplify its support.

I often create a subfolder for each controller, so I get things like Web.Models.Foo.BarViewModel .

+4
source

If they are in my Domain project in the PresentationModel directory and, like @Seth Pretry-Johnson, I have them in separate controller directories.

This is my overall project structure:

  • Website design
    • Controllers
    • representation
    • Etc
  • Domain project
    • Models
    • Storage facilities
      • annotation
    • Services
      • annotation
    • PresentationModels
      • home
      • User
      • Etc
  • DataAccess Project
    • Storage facilities

HTHs ( ..;-),

+3

"".

/Controllers
/Models
    /Entities
    /Mappings
    /ValueTypes
    /ViewModels

- . Fluent NHibernate.

0

, , - , ?

, , - , , . , ASP.NET MVC . .

0

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


All Articles