Does it Make Sense to have ViewModels in the Webapi?

前端 未结 5 1444
生来不讨喜
生来不讨喜 2020-12-23 15:44

I am starting to learn the webapi and find myself doing stuff that makes sense in an MVC project but may not make sense in.

Normally in an MVC project I make ViewMod

5条回答
  •  暖寄归人
    2020-12-23 16:43

    Just to add what others have said, the use of what would normally be termed a ViewModel is useful for validation as well. You can mark up your classes with data annotations including any validation requirements. In your controller actions you can still use ModelState to force the validation to occur and return appropriate messages via HttpRequestException or just HttpResponseMessage.

提交回复
热议问题