MVC中,查询以异步呈现,分页不用异步的解决方案

这种需求,用一个ASPX页面和一个ASCX分部视图就可以解决了,ASPX提供对ASCX的引用,ASCX显示列表信息,ASPX主页面提供查询功能

  <% using (Html.BeginForm())
       {%>
    <%Html.RenderAction("AllPropertyForSelectList", "Common"); %><input type="button"
        value="查询" class="button" id="search" />
    <div id="list">
        <%Html.RenderPartial("Common_BasePropValueList",Model); %>
    </div>
    <%} %>

查询功能的JS

<script type="text/javascript">
        $(function () {
            $("#search").click(function () {
                $.ajax({
                    type: "POST",
                    url: "/Common_BaseProp/Index",
                    data: { page: "<%=Model.PageIndex %>", pid: $("#PID").val() },
                    success: function (data) {
                        $("#list").html(data);
                    }
                })
            });
        });
    </script>

controller代码:

  public ActionResult Index(int? page, int? pid)
        {
            vp = new Entity.VPredication();
            pp = new Entity.PagingParam(page ?? 1, PAGESIZE);
            if (pid != null)
                vp.AddItem("pid", pid);
            Entity.PagedList<Common_BasePropValue_Ext> model = iCommon_BasePropValueService.GetAllBasePropValue(vp, pp);
            if (Request.IsAjaxRequest()) //通过判断请求,来确定是返回页面,还是返回分部视图
                return PartialView("Common_BasePropValueList",model);
            else
                return View(model);
        }

posted @   张占岭  阅读(1087)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
点击右上角即可分享
微信分享提示