ASP.NET MVC: ModelState vs. ModelStateDictionary

前端 未结 6 1681
予麋鹿
予麋鹿 2021-02-04 09:32

I have a service which has a method that\'s called when a certain controller method is triggered.

My service returns a custom result object PlacementResult in w

6条回答
  •  鱼传尺愫
    2021-02-04 10:01

    No, you do not want to add a ModelStateDictionary to your result type. There is already a ModelStateDictionary on the Controller (in the ModelState property). It is not appropriate for results to set the controller's model state. That should be done during binding or within the controller action itself. Use a custom model binder if you need to.

    Your choose one can see the model state errors by examining the controller's ViewData.ModelState property.

提交回复
热议问题