页面加载后,局部呈现局部、加载、页面

2023-09-10 19:39:32 作者:我是绝版我骄傲

我有一个包含一些用户控件的页面。我想回发就像一个Ajax渲染后加载这些用户控件。

I have a page that contains some usercontrols. I would like to load these usercontrols after postback like an ajax rendering.

每个用户控件显示来自数据库的清单,我不希望用户等待服务器code建立起来,我认为这将是有用的,如果显示的页面为用户和用户控件后,通过加载响应Ajax请求。

Each usercontrols display a list from database and I dont want the user to wait while server code builds up the response I think it will be useful if the page is displayed for the user and after the usercontrols are loaded through an ajax request.

有没有在ASP.NET MVC的存在解决方案吗?是否有这一问题的存在解决办法?

Is there an exist solution in ASP.NET MVC? Is there an exist solution for this problem?

由于事先:→

推荐答案

我通常是这样的:

在标记我预留空间,为用户控制,应像

In the markup I reserve space for the user control to be loaded like

<div id="i-tabs-5">
    <div style="text-align:right;margin-bottom:6px;">...</div>
    <div id="issueNoteListPlaceholder"></div>
</div>

然后在DOM准备好我做一个AJAX调用返回的局部视图的结果,替换占位符的内容

then on DOM Ready I make an ajax call that return a partial view result and replace the content of the placeholder

$(document).ready(function () {
    loadIssueNotes();
});

function loadIssueNotes() {
    $.ajax({
        type: "get",
        dataType: "html",
        url: '<%: Url.Content("~/Controller/Action") %>',
        data: {},
        success: function (response) {
            $("#issueNoteListPlaceholder").html('').html(response);
        }
    });
}