How to integrate an ASP.NET Model View Presenter (MVP) template and static page methods marked as [WebMethod]?

In an asp.net application, I would like to combine the use of Webclient Factory (WCSF) software and its associated Model View Representation Template (MVP) using a page method, which is static methods. aspx Views tagged with the [WebMethod] attribute.

However, the static methods on the aspx page seem to violate the Model View Presenter pattern because the page requires an instance method in order to have the Presenter and Controller context needed to view it.

How would one advanced ASP MVP template in WCSF support [WebMethods] on a page, such as View?

+4
source share
2 answers

I had a similar problem recently when I was running an MVP project and wanted a lot of AJAX integration. It is best to have web services that match the MVP pattern that you are calling.

Keep in mind that PageMethod is more than a web service, only on the current page. It does not have access to page-level objects, so the benefits of having it are minimal. I really think that they are at a disadvantage, they give developers (who are not familiar with the concept) the idea that they can interact with page-level objects.

The flip side of the coin is what your PageMethod does if your page method does not need to interact with the Model (say, it handles complex arithmetic calculations that are faster in C # / VB.NET than JS), then the operation is really UI-level operation and most likely irresponsible if you must turn the application into WinForm (or something else).

Keep in mind that all interaction with data at the user interface level is specific to the implementation of this interface. If you want to write a different interface for speakers, then most likely you will have different interactions of user interface level data.

+4
source

I think you can get closer to what you are looking for using the ASP.Net AJAX web service instead of the static page methods. The advantage of a web service is that it is not static, and depending on how your views are implemented (I am not familiar with the specification of the MVS WCSF template), you can make the web service your own View layer ... or at least something pretty close.

I did something similar in the project I'm working on. In the end, I had to create a thin class only for data that was passed to JSON using a web service to transfer data from the model to the β€œview”, but the web service had essentially the same methods that would be presented as events by the look.

One of the things that I liked about this approach is that all the bits, including the web service, can be checked.

+2
source

Source: https://habr.com/ru/post/1277231/


All Articles