Is there a way to partially view MVC obtained with jQuery to preserve CSS UI styles?

I have an MVC 2 project consisting of a MasterPageView of a child view called Index and a PartialView series. PartialViews are loaded into the index view using the jQuery Ajax $ .get (....) method.

My problem is that I am customizing buttons using jQuery UI, for example:

$('button').button();

but I believe that I need to do this on every PartialView. What I would like to do is define it once in MasterPageView, but if I do, the style will be lost. I guess this is because the style is applied before loading the DOM, is this correct? Is there a way to implement this, that is, just define it on MasterPageView?

Thanks for the help!

+3
source share
1 answer

This does not work when objects are added to the DOM after the initial load. In these cases, you need to move on to the new .live () syntax in jQuery:

$("button").live("load", function(){
    $(this).button();
});

It listens for new objects added to the DOM and attaches an event handler to it.

Hope this helps!

+2
source

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


All Articles