天天看點

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);

        }

繼續閱讀