Asp – How to integrate the ASP .Net Model View Presenter (MVP) pattern and static page methods marked as [WebMethod]

asp.netjsonmvpwcsf

In an asp.net application, I would like to combine the use of the Webclient Software Factory (WCSF), and its associated Model View Presenter pattern (MVP), with Page Method, that is static methods on the .aspx Views marked with the [WebMethod] attribute.

However, static methods on the aspx page would seem to break the Model View Presenter pattern since an instance method is required on the page to have the context of the Presenter and Controller necessary for the View to talk to.

How would one extended asp .net's MVP pattern in WCSF to support [WebMethods] on the page, aka the View?

Best Answer

I had a similar problem recently when doing a MVP patterened project and wanting a lot of AJAX integration. You're best off having web services which conform to the MVP pattern that you call.

Keep in mind that a PageMethod is little more than a web service, just in the current page. It doesn't have access to any page-level objects so the advantages of having it there are minimal. I actually think they are disadvantagious, they give developers (who are unfamiliar with the concept) the idea that they can interact with page-level objects.

The flip-side of the coin is what your PageMethod is doing, if your page method is not needing to interact with the Model (say, it's handling complex arithmatic calculations which are faster in C#/VB.NET than JS) then the operation is really a UI level operation and quite probably irrelivant if you were to turn the app into a WinForm (or something else).

Keep in mind that all interaction with data at a UI level is specific for that UI implementation. If you were to write a different UI for the presenters then chances are you'll have different UI level data interaction.

Related Topic