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>
  • 相关阅读:
    jenkins1—docker快速搭建jenkins环境
    UPC-6616 Small Multiple(BFS广搜&双向队列)
    UPC-5502 打地鼠游戏(贪心&优先队列)
    UPC-5500 经营与开发(贪心&逆推)
    NBUT
    UPC-6690 Transit Tree Path(树上最短路径SPFA)
    UPC-6359 售票(字典树)
    UPC-6358 庭师的利刃(两数与运算最大值)
    HDU-6308 Time Zone(时区转换)
    欧拉函数模板及拓展
  • 原文地址:https://www.cnblogs.com/lori/p/2235736.html
Copyright © 2011-2022 走看看