0

在单击按钮时,我使用 jquery $.ajax 获取一些数据,调用控制器操作方法并返回强类型的局部视图。数据显示在表格中。

当数据可用时,我还需要呈现另一个强类型的局部视图(与 resultSetView 的模型相同)以显示 resultSetView 的页面导航按钮。

我该怎么做第二部分?

$.ajax({
            type: "POST",
            url: $form.attr('action'),
            data: $form.serialize(),
            error: function (xhr, status, error) {
                //do something about the error   
            },
            success: function (response) {
                $("#resultSetDiv").html(response);
                //need to reload pageNavigationDiv
            }
        });

标记就像

<div id="pageNavigation >
    @Html.Partial("_pageNavigationView")
</div>
<div id="resultSetDiv">
     @RenderSection("_resultSetView")
</div>
4

1 回答 1

0

JSON以以下格式从您的操作方法发送响应

{
    "success": "true",
    "currentPage": "3",
    "totalPages": "12",
    "viewString": "<div>Somecontent</div>"
}

viewString 中的值将是要加载到 resultSetDiv 的 HTML 标记。

success: function (response) {
          if(response.sucesss=="true")
          {
              $("#resultSetDiv").html(response.viewString);
              $("#yourPageNumber").html(response.currentPage);
          }
}

这个答案解释了如何以 JSON 格式发送 ViewResult

于 2012-09-13T18:42:40.097 回答