Where does jQuery UI fit in MVC?

I need to develop a generic jQuery-based search plugin for an ASP.NET MVC application that I am creating, but I cannot figure out how it should fit, or best practice. I want to do the following:

$().ready(function() { $('#searchHolder').customSearch('MyApp.Models.User'); }); 

While I have implemented a specific interface on Model.User, jQuery will be able to talk to the reflection service in order to build the corresponding user interface as a whole.

Sounds funny, but it seems like I'm now invoking JavaScript from a view, which in turn will perform some View-related actions to create a search user interface, and then to search and interact with the user, he is going to drop a bunch of Controller tasks there.

So where does this really fit? Is there any other way to structure my jQuery plugin to fit the idea of ​​MVC? Does MVC work when it scales to its own form in another MVC structure? Should I just ignore these issues for the sake of a single plugin?

+4
source share
5 answers

Just to keep an eye on (I’m very surprised that someone else didn’t have any opinions about this), to preserve the best practice, I decided to adopt jTemplates .

This allows me to request JSON style models from my server controller and process it using syntax similar to the one I would already use in a view that now supports any required JavaScript UI MVC-compatible. There is little overhead for the client having to request the View template from the server, but if it gets too slow, I can always donate a bit and send it using the initial JSON request.

+2
source

It seems to me that you want partials , the term RoR, so you are not sure that they exist in the same format in ASP.NET MVC. Basically, the partial part is part of the view, which is defined in its own file and can be called from anywhere. Thus, in your search controller, you pull out the requested model, do some reflection to get the data and build it in JSON, and also capture a partial view for this model. It may be easier for you if you follow the partial file naming convention based on the model name to save you in any large switch or additional configuration files.

I could be wrong, but it looks like you are a little worried about calling the controller from Javascript and getting the HTML code. This is completely normal, this is just the case when you select View correctly and make sure that you are not processing the rest of the page, just what you need for this call (why MVC is much better than UpdatePanel s!)

+1
source

so I actually understand a lot about this, and found that the new officially supported jQuery tmpl plugin can work as a viewer. I wrote a tutorial here how you can create a complete MVC / MVP paradigm in JavaScript

+1
source

I'm not sure I understand what you're trying to accomplish, but I would build the appropriate user interface on the server as part of your view (for example, as a user control that can appear on different pages), set its display: none style and use jQuery on the client side to show it when the user clicks on any link or something else.

After that, the plugin will use $ .ajax to send a search request to your application, where you can perform the appropriate actions and display a partial view with the search result. Then your ajax code picks it up and inserts it into the document.

0
source

Approach it as if you had two separate systems with models, views and controllers on the server and (Javascript / DOM) models, views and controllers on the client (browser). Ajax is just a client-side method for requesting services from a server.

0
source

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


All Articles