jquery - Ajax Refreshing Partial View -
i'm trying refresh partial menu depending on user selection through ajax.
i have authenticated layout has this...
<div class="container-fluid body-content"> <div class="row"> <div class="col-lg-offset-2 col-md-offset-2 col-sm-offset-2 col-lg-10 col-md-10 col-sm-10 col-xs-10"> <div id="bodycontent" class="pad-top"> @renderbody() </div> </div> <div id="menu" style="display: inline; visibility: hidden"> @{ html.renderaction("getmenupartial", "menu", noarea); } </div> </div>
then inside renderaction controller, can render few different menus depending on user role.
public partialviewresult getmenupartial() { if (user.isinrole(roles.applicationcenter.administrator)) { return !string.isnullorempty(sessionhelper.getimpersonationname()) ? getapplypartial() : partialview("_menuadminpartial", geturl()); } if (user.isinrole(roles.applicationcenter.customer)) { return partialview("_menucustomerpartial", getmenucustomerviewmodel()); } return sessionhelper.getapplicationid() == 0 ? partialview("_menucandidatepartial", getmenucandidateviewmodel()) : getapplypartial(); }
my request refresh partial looks this...
$.get('@url.action("getmenupartial", "menu", new {area = ""})', {}) .done(function(menucustomerviewmodel) { $("#menu").html(menucustomerviewmodel); });
i'm able refresh partial, however, doing messes layout of partial. i'm assuming it's no longer loading css on div elemenet partial view located in. point me right direction how better handle this?
you can create wrapper around menu, this:
<div id="menucontainer"><div id="menu"....
and use #menucontainer set html
or can try replacewith instead of html:
$("#menu").replacewith(menucustomerviewmodel);
hope helps.
Comments
Post a Comment