weixin_33726318 2015-08-19 17:47 采纳率: 0%
浏览 50

Ajax刷新局部视图

I'm trying to refresh a partial menu depending on the user selection through Ajax.

I have an authenticated layout that 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 that RenderAction is my controller, which can render a 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 GET request to refresh the partial looks like this...

    $.get('@Url.Action("GetMenuPartial", "Menu", new {area = ""})', {})
                        .done(function(menuCustomerViewModel) {
                        $("#menu").html(menuCustomerViewModel);
                    }); 

I'm able to refresh the partial, however, doing this messes up the layout of the partial. I'm assuming it's no longer loading the CSS on that div elemenet the partial view is located in. Could someone point me to the right direction as to how to better handle this?

  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 macOS使用IDEA 2022.2.4打包JDK6项目报错
      • ¥20 OpenCV-Python简单轮廓寻找
      • ¥20 使用matlab进行含参数的最优化求解及数值模拟
      • ¥20 MATLAB找出一维变量中的局部极大值和局部极小值,并进行运算
      • ¥15 有Chang求三维杆单元几何非线性分析matlab代码
      • ¥50 使用unity easyar录屏功能。录屏视频整体色调很暗
      • ¥50 pyinstaller 打包问题
      • ¥15 无法使用cnssc调取网页数据
      • ¥15 Pycharm安装en_core_web_sm失败出现Could not find a version that satisfies the requirement spacy报错
      • ¥15 Python社区划分