zoukankan      html  css  js  c++  java
  • MVC中实现部分内容异步加载

    action中定义一个得到结果集的方法
       

     public ActionResult GetItemTree(string title, int itemid, int? page)
            {
                pp = new PagingParam(page ?? 1, VConfig.WebConstConfig.PageSize);
                Common.Page.PagedList<Entity.Res_Item_Resource_R> res_Item_Resource_R = iResourceService.GetRes_Item_Resource_RByItemId(itemid, pp);
                ViewData["res_Item_Resource_R"] = res_Item_Resource_R;
                res_Item_Resource_R.AddParameters = new System.Collections.Specialized.NameValueCollection();
                res_Item_Resource_R.AddParameters.Add("title", title);
                res_Item_Resource_R.AddParameters.Add("itemid", itemid.ToString());
    
                ViewResult vr = new ViewResult
                {
                    ViewData = ViewData,
                    MasterName = "",
                };
                return vr;
            }


        在主页面使用下面jquery代码异步调用上面的action
          

      $(function () {
            var id = '<%=itemid %>';
            $.ajax({
                type: "POST",
                url: "/Student/GetItemTree",
                data: { title: '<%=Model.Name %>', itemid: id, page: 1 },
                beforeSend: function (data) { //取回数据前
                    $("#itemTree").html('<span style="padding:5">数据加载中...</span>');
                },
                error: function (data) { //发生错误时
    //                debugger;
                },
                success: function (data) { //成功返回时
                    $("#itemTree").html(data);
                }
            });


       最后在分部视图GetItemTree.ascx中写上你要返回的数据结构即可
       注意一点就是,如果涉及到分页,要用AJAX分页方式

       <div style="float: left">
            <%=Html.AjaxPager(resItemResourceBefore, "itemTree", "GetItemTree", "Student")%>
        </div>
  • 相关阅读:
    iOS开发UI篇—UITabBarController简单介绍
    iOS 开发 UI 搭建心得(一)—— 驾驭 StoryBoard
    The Swift Programming Language--语言指南--协议
    Swift 委托/代理设计模式
    Ping azure
    leetcode先刷_Maximum Subarray
    AsyncHandler
    HDU 1026 Ignatius and the Princess I 迷宫范围内的搜索剪枝问题
    Design Pattern Command 命令设计模式
    logstash高速入口
  • 原文地址:https://www.cnblogs.com/lori/p/2235736.html
Copyright © 2011-2022 走看看