Uses jquery to call a WCF data service from a user interface that violates the MVC pattern

I am new to ASP.Net MVC 2 and understand the MVC pattern by itself. But my question is, what is the best way to populate dropdownlists in a user interface that adheres to the MVC pattern. Do I have to go through the controller?

Each article I saw shows how to do this using javascript and jquery. I have a test application that I am rewriting in MVC2. I have my dropdown menus working with jquery, basically calling the WCF data service, which returns a JSON that populates the dropdown lists. It seems to me that this bypasses the controller and goes directly to the model, therefore it strictly violates the MVC pattern.

Or I'll miss something obvious here. We will be very happy for your thoughts or best practices.

thank

+3
source share
3 answers

One of the great features of MVC is that the controllers can connect as "web services" or sort. So, you can easily specify the return type "JsonResult", for example (instead of a view, ActionResult).

The MVC framework will handle all serialization for you.

You can easily call the controller action method from jQuery and populate the dropdown menu.

Json, ( HTTP, json http get ..), jQuery .

+3

(.. ), AvailableItems , . , AJAX - .

, script , , . MVC.

0

, .

. , , ajax? , javascript .

IEnumerable<String> CityNames, .

0

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


All Articles