ASP.NET MVC: ModelState vs. ModelStateDictionary

前端 未结 6 1685
予麋鹿
予麋鹿 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

    I don't know what your PlacementResult looks like, see if you can possibly utilize this in your view:

    ModelState.AddModelError(ErroredProperty, ErrorMessage);
    

    Make sure you return the object that failed back to the view

    return View(myObjectInstance);
    

提交回复
热议问题