質問

I'm on Microsoft MVC4, I'm starting to have a lot of models and i want to reorganize them.

I'm heavily using jQuery Ajax calls to populate data, thus I have:

  • few actions that returns simple views (i.e. empty html tables)

  • many actions that return a JsonResult, used to populate tables/listitems and so on

In some action the same element ( 'item' ) is shown with some information( i.e. columns ), in other actions it is shown with other informations.

My two questions:

  • should I have a Model for each action that returns a Json Result, for clarity? or i should not bother, and I should use continue using anonymous projection?

  • should I have base Models (i.e. the 'simple' ones) and extended models that inherit from base Models? or should i keep the Models sperated, resulting in a cleaner (but less maintenable?) structure?

Thank you!

役に立ちましたか?

解決

should I have a Model for each action that returns a Json Result, for clarity? or i should not bother, and I should use continue using anonymous projection?

Anonymous project is just fine for JSON results. Makes unit testing a bit harder but it's up to you to decide whether you want to introduce a view model here.

Should I have base Models (i.e. the 'simple' ones) and extended models that inherit from base Models? or should i keep the Models sperated, resulting in a cleaner (but less maintenable?) structure?

You could have inheritance in your view models.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top