ASP.NET MVC:主场迎战的ModelState ModelStateDictionary [英] ASP.NET MVC: ModelState vs. ModelStateDictionary
问题描述
我有其中有一个被触发时一定控制方法的调用方法的服务。
I have a service which has a method that's called when a certain controller method is triggered.
我的服务会返回一个自定义的结果对象的 PlacementResult 的中,我想回去传达可能发生错误(验证)到控制器的方法。
My service returns a custom result object PlacementResult in which I want to communicate errors that may have happened (validation) back to the controller method.
应该 PlacementResult 的具有的ModelState或ModelStateDictionary通信错误返回给控制器(和最后查看)?如何将我这串起来?
Should PlacementResult have a ModelState or a ModelStateDictionary to communicate errors back to the controller (and finally view)? How would I string this together?
最后,我怎么得到的ModelState / ModelStateDictionary(无论你告诉我,我应该选择)回视图(突出显示相应的文本框中,显示错误消息等等)?
Finally, how do I get the ModelState/ModelStateDictionary (whichever you tell me I should choose) back into the view (highlighting the appropriate text box, show the error message etc.)?
感谢您!
推荐答案
这是一个很好的链接,显示了服务如何进行验证和沟通的结果反馈给控制器:
This is a good link that shows how a service can perform validation and communicate the result back to the controller:
http://www.asp.net/ MVC /教程/验证上带有一个服务层-CS (固定链接)
这篇关于ASP.NET MVC:主场迎战的ModelState ModelStateDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!