javascriptjqueryasp.net-mvcpartial-viewsajax.beginform

MVC Ajax.BeginForm on Partial View ejecute function on Parent View update Parent View


I am doing MVC App. I have a View that call a Partial View as DialogPopUp.

That View execute a @Ajax.BeginForm. On Success it calls a javascript function defined in Parent View becouse there are not allow javascript un PartialView. That function makes <div hiddden> visible, and viceversa.

 $(".hidden").toggleClass("hidden visible");

the problem I found, that I have <div hiddden> also in Parent View. So, when function is called, is works on both divs...(in Parent and in PartialView).

Is there a way that it is ejecuted only in PartialView?


Solution

  • You could wrap your partial view contents in a div:

    <div class="myPartialWrapper">
        ... your partial markup comes here
    </div>
    

    and then adapt your selector:

    $(".myPartialWrapper .hidden").toggleClass("hidden visible");