0
public ActionResult Index(int directoryID)
{
    Someclass sc = new Someclass();
    DataTable dt = sc.method("directory");

    return View(dt);
}

public ActionResult PlotPartial(DataTable dt)
{
    return PartialView(dt);
}

上面的索引方法返回一个数据表到 IndexView 工作正常。在同一个视图中,我有一个按钮,它应该加载 PartialView“PlotPartial”,传递整个模型,即数据表。如何在不创建数据表实例两次的情况下最有效地实现这一点。我可以在两种操作方法中共享数据表吗?我想要部分视图中的整个数据表。它没有任何 id 列。

阿贾克斯代码:

$('#btnPlot').click(function () {
            $.ajax({
                url: '/Home/PlotPartial',
                contentType: 'application/html; charset=utf-8',
                data: { dt : @model },
                type: 'GET',
                dataType: 'html'
            })
            .success(function (result) {
                $('#panelB').html(result);
            })
            .error(function (xhr, status) {
                alert(status);
            })
        });

在上面的代码行“数据:{ dt:@model }”不起作用。

有人可以帮忙吗

4

1 回答 1

1

由于您将整个 DataTable 传回,而不是从数据库中提取新版本,因此根本没有理由为此使用 ajax。

在您的视图中,继续渲染 PlotPartial 视图。

<div id='OriginalContent' class='ReplacableContent'>
    // Put the initial content here
</div>
<div id='PlotPartial1' style='display:none' class='ReplacableContent'>
    @Html.Partial("PlotPartial1", Model)
</div>
<div id='PlotPartial2' style='display:none' class='ReplacableContent'>
    @Html.Partial("PlotPartial2", Model)
</div>
<div id='PlotPartial3' style='display:none' class='ReplacableContent'>
    @Html.Partial("PlotPartial3", Model)
</div>
<div id='PlotPartial4' style='display:none' class='ReplacableContent'>
    @Html.Partial("PlotPartial4", Model)
</div>
<div id='Controls'>
    //Put your buttons here
</div>

每个按钮应该做这样的事情:

$(".ReplacableContent").hide(); // Hide everything else
$("PlotPartial1").show(); // Show the indicated partial

(已更新以解决评论中的请求。)

于 2013-10-29T15:08:32.637 回答