ASP.net MVC - One ViewModel per View or per Action?

前端 未结 4 582
我寻月下人不归
我寻月下人不归 2020-12-31 07:27

Is it a better idea to have a single ViewModel per view or one per controller action?

Example:

public ProjectController : Controller
{
    public Act         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-31 07:50

    Use different model to receive input parameters in Post action (I don't even call it ViewModel in that case) than to pass output parameters to the view.

    That way you can customize exactly what input parameters do you accept.

提交回复
热议问题