MVC模式中,如何使用AJAX進行分頁

來源:互聯網
上載者:User

列表首頁Action內容:

  public ActionResult HelpList()
        {
            Entity.Commons.VPredication vp = new Entity.Commons.VPredication();
            Entity.Commons.PagingParam pp = new Entity.Commons.PagingParam(1, 10);
            Entity.PagedList<Entity.HelpDocument> list = _HelpDocumentServices.GetHelpDocument(vp, pp);
            List<Entity.HelpCategory> clist = _HelpDocumentServices.GetAllCatetories();
            clist.Insert(0, new Entity.HelpCategory() { HelpCategoryID = "", CategoryName = "選擇類別" });
             ViewData["Category"] = clist;
            return View(list);
        }

列表使用者控制頁Action內容:

 public ActionResult PageHelp(int? pi, string title, string cid)
        {
            Entity.Commons.VPredication vp = new Entity.Commons.VPredication();
            Entity.Commons.PagingParam pp = new Entity.Commons.PagingParam(pi ?? 1, 10);
            if (!string.IsNullOrEmpty(title))
                vp.AddItem("Title", title);
            if (!string.IsNullOrEmpty(cid))
                vp.AddItem("HelpCategoryID", cid);
            Entity.PagedList<Entity.HelpDocument> list = _HelpDocumentServices.GetHelpDocument(vp, pp);
            list.AddParameters = new System.Collections.Specialized.NameValueCollection();
            list.AddParameters.Add("title", title);
            list.AddParameters.Add("cid", cid);
            return PartialView("LelpItemList", list);
        }

ASPX檔案:

<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
     <script type="text/javascript">
         $(function() {
             $('#search_btn').click(function() {
                 var title = $('#Title').val();
                 var cid = $('#CategoryList').val();
                 $.ajax({
                     type: "POST",
                     url: "/Help/PageHelp",
                     data: "pi=1&title=" + title + "&cid=" + cid,
                     success: function(data) {
                         $('#helpitem_div').html(data);
                     }
                 });
             })
         })
 
    </script>
    <script src="http://www.cnblogs.com/Scripts/js/Help/DelHelp.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h1>
        <span class="action-span1"><a href="/">管理中心</a> - 協助管理 </span>
    </h1>
    <div>
        標題:<input id="Title" type="text" />分類:
        <select id="CategoryList" name="CategoryList">
            <%foreach (var i in ViewData["Category"] as List<Entity.HelpCategory>)
              {
            %>
            <option value="<%=i.HelpCategoryID %>" style="color: #339; background-color: #eee;">
                <%=i.CategoryName%>
            </option>
            <%
                if (i.SubCategoryies != null)
                {
                    foreach (var ii in i.SubCategoryies)
                    {    
            %>
            <option value="<%=ii.HelpCategoryID %>">&nbsp;&nbsp;=><%=ii.CategoryName%>
            </option>
            <%}
                }
              } %>
        </select>
        <input id="search_btn" class="button" type="button" value="查詢" /></div>
    <div id="helpitem_div">
        <%Html.RenderPartial("LelpItemList", Model); %>
       
    </div>
</asp:Content>

ASCX檔案內容:

 
<script type="text/javascript">
    //連結始終在一個視窗中開啟
    function ActiveWin(url) {
        var w = screen.availWidth;
        var h = screen.availHeight;
        var popup = window.open(url, "win_name", "top=0 left=0 scrollbars=yes status=no menubar=0 toolbar=0 resizable=yes");
        popup.focus();
        return false;
    }
</script>
 
<script src="http://www.cnblogs.com/Scripts/js/liebiao_table.js" type="text/javascript"></script>
 
<table width="100%" id="" cellpadding="3" cellspacing="1" class="liebiao_table">
    <thead>
        <tr>
            <th>
                標題
            </th>
            <th>
                分類
            </th>
            <th>
                排序
            </th>
            <th>
                建立時間
            </th>
            <th>
                操作
            </th>
        </tr>
    </thead>
    <tbody>
        <%foreach (var item in Model)
          {
        %>
        <tr>
            <td>
                <a href="/help/HelpDetail?helpid=<%=item.HelpDocumentID %>">
                    <%=item.Title %></a>
            </td>
            <td>
                <%=item.HelpCategory.FatherCategory.CategoryName %>=><%=item.HelpCategory.CategoryName %>
            </td>
            <td align="center">
                <%=item.SortNumber %>
            </td>
            <td align="center">
                <%=item.CreateDate %>
            </td>
            <td align="center">
                <a href="javascript:void(0)" onclick="ActiveWin('/help/HelpDetail?helpid=<%=item.HelpDocumentID %>')">
                    查看</a>&nbsp;&nbsp;<a href="javascript:void(0)" onclick="ActiveWin('/Help/EditHelp?hid=<%=item.HelpDocumentID %>')">編輯</a>&nbsp;&nbsp<a
                        href="javascript:void(0)" onclick="DelHtml('<%=Model.PageIndex %>','<%=item.HelpDocumentID %>')">刪除</a>
            </td>
        </tr>
        <%
            } 
        %>
    </tbody>
</table>
<%=Html.AjaxPager(Model, "helpitem_div", "PageHelp", "Help")%>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.