ASP.NET MVC terminology is tripping me up - why 'ViewModel'?

前端 未结 5 504
你的背包
你的背包 2020-12-14 12:45

I\'m an ASP.NET MVC newbie, but have used many Model-View-Controller frameworks previously.

I recently came across the convention of gathering up the pieces of data

5条回答
  •  误落风尘
    2020-12-14 13:40

    Re: why can't the controller populate properties on the view?

    Because the view doesn't exist at the time the controller action is executing. The idea behind returning an ActionResult from your action is that something later in the processing pipeline will evaluate the result and determine the best course of action (perhaps rendering a view, or maybe selecting a view to match the request (like special views made for mobile devices)).

    I did a view posts on selecting the right kind of model object here: Putting the M in MVC Part I, Part II, Part III.

    And yes, the term "ViewModel" term is en vogue right now, but it is in the spirit the original MVC adopters had in mind.

提交回复
热议问题