简体   繁体   English

在现有局部视图上渲染新的局部视图

[英]Render a new partial view on existing partial view

I am trying to do a drill down report. 我正在尝试进行深入报告。 I am using MVC and Devexpress Gridviews. 我正在使用MVC和Devexpress Gridviews。 I render my view and the partial view and display my gridview with the result. 我渲染我的视图和局部视图,并显示带有结果的gridview。

Now what I need to accomplished is when I double click on the gridview I need to render a new/different partial view in the place off the existing gridview - The one I double clicked on. 现在我需要完成的是,当我双击gridview时,我需要在现有gridview的地方渲染一个新的/不同的局部视图-我双击了一个。

Is this possible? 这可能吗?

Here is what I have: 这是我所拥有的:

    public ActionResult MainPartial()
    {  
        using (var Context = new DataContext())
        {
            ViewBag.Level = 0;
            return PartialView("MainPartial",SomeData);
        }
    }

    public ActionResult FirstDrilldownPartial(int Param)
    {  
        using (var Context = new DataContext())
        {
            ViewBag.Level = 1;
            return PartialView("FirstDrilldownPartial",SomeNewData(Param));
        }
    }

My Gridview RowDblClick event 我的Gridview RowDblClick事件

function onDoubleClick(s, e) {

    $.ajax({
        type: 'POST',
        url: '/Controler/FirstDrilldownPartial',
        dataType: 'json',
        async: false,
        //cache: false,
        data: {
            Param: 1
        }
    });
}

At the moment everything is working but when I call the function "function onDoubleClick(s, e)" the Main grid stay on the view and the new grid is not rendered. 目前一切正常,但是当我调用函数“ function onDoubleClick(s,e)”时 ,主网格仍停留在视图上,而新的网格未呈现。

Can someone please help with suggestions. 有人可以提供建议吗?

Thanks 谢谢

You can render both partials in different divs and hide or show in your js function a div, for example 您可以在不同的div中渲染两个部分,并在js函数中隐藏或显示div,例如

<div id="mydiv1">
    @Html.Partial("Partial1")
<div>
<div id="mydiv2">
    @Html.Partial("Partial2")
</div>

and in your onDoubleClick ( I assume that you are using jQuery) 并在您的onDoubleClick中(我假设您正在使用jQuery)

$("#mydiv1").hide();
$("#mydiv2").show();

and to hide (on page load) the second div first just add 并隐藏(在页面加载时)第二个div首先只需添加

$(function () {
     $("#mydiv2").hide();
});

or use 或使用

<div id="mydiv2" style="display:none;">

This code is not tested, but it should work. 该代码未经测试,但可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM