ASP.NET MVP and AJAX posting/webservices

纵然是瞬间 提交于 2019-12-21 06:28:14

问题


When applying the MVP pattern to ASP.NET applications, where does using AJAX to post data fit? Of what I know of the MVP pattern, the UI is simply that(appearance), and all the heavy lifting is done in the presenter. I don't see how you could follow the pattern and still use AJAX interacting with web services on the client. Does anyone have any references as to how one can use AJAX and web services and still follow the MVP pattern?

Thanks!


回答1:


I use the same approach with AJAX as with a regular ASP.Net post back. The view receives the post but passes it to the presenter that handles the processing. In the view I just parse the request coming from AJAX and then invoke the appropriate method on the Presenter class.

A web service can be considered as a view that "renders" a message instead of rendering HTML. I treat the web service as the view and use a presenter the same way as with an ASPX page, with the added advantage that I don't need to parse the request.

I decouple the presenter from the message leaving for the web service the responsibility of creating the return message from the view data assigned by the presenter. The input message is also known only at the web service level.



来源:https://stackoverflow.com/questions/732837/asp-net-mvp-and-ajax-posting-webservices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!