Csharp:Paging Sorting Searching In ASP.NET MVC 5

来源:http://www.cnblogs.com/geovindu/archive/2017/11/23/7883697.html
-Advertisement-
Play Games

http://www.c-sharpcorner.com/UploadFile/0c1bb2/sorting-paging-searching-in-Asp-Net-mvc-5/ https://dzone.com/articles/table-sorting-pagination Index.cs ...


http://www.c-sharpcorner.com/UploadFile/0c1bb2/sorting-paging-searching-in-Asp-Net-mvc-5/

https://dzone.com/articles/table-sorting-pagination

https://datatables.net/

 

Index.cshtm:

@{
    ViewBag.Title = "Paging Sorting Searching In ASP.NET MVC 5";
}
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<link rel="stylesheet" type="text/css" href="~/css/jquery.dataTables.min.css">
<script type="text/javascript" language="javascript" src="~/Scripts/jquery.dataTables.min.zh.js" charset="utf-8"></script>
<script>

    $(document).ready(function () {
        //Call EmpDetails jsonResult Method  http://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css
        $.getJSON("Home/EmpDetails",
        function (json) {
            var tr;

        //Append each row to html table
        for (var i = 0; i < json.length; i++) {
                tr = $('<tr/>');
                tr.append("<td>" + json[i].Id + "</td>");
                tr.append("<td>" + json[i].Name + "</td>");
                tr.append("<td>" + json[i].City + "</td>");
                tr.append("<td>" + json[i].Address + "</td>");
                $('table').append(tr);

        }
        $('#EmpInfo').DataTable();
        });

    });

</script>
<hr />
<div class="form-horizontal">
    <table id="EmpInfo" class="table table-bordered  table-hover">
        <thead>
            <tr>
                <th>Id</th>
                <th>Name</th>
                <th>City</th>
                <th>Address</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>  

</div>

  _Layout.cshtml:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - www.dusystem.com 捷為工作室</title>
    <link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <script src="~/Scripts/modernizr-2.6.2.js"></script>

</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("www.dusystem.com 捷為工作室", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                </ul>
            </div>
        </div>
    </div>

    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>© @DateTime.Now.Year - www.dusystem.com 捷為工作室</p>
        </footer>
    </div>


    <script src="~/Scripts/bootstrap.min.js"></script>
</body>
</html>

  HomeController.cs:

using PagingSoringInMVC.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace PagingSoringInMVC.Controllers
{

    /// <summary>
    /// 
    /// </summary>
    public class HomeController : Controller
    {
        // GET: Home
        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public JsonResult EmpDetails()
        {
            //Creating List    
            List<Employee> ObjEmp = new List<Employee>()
        {  
            //Adding records to list    
            new Employee
            {
                Id = 1, Name = "Vithal Wadje", City = "Latur", Address = "Kabansangvi"
            },
            new Employee
            {
                Id = 2, Name = "Sudhir Wadje", City = "Mumbai", Address = "Kurla"
            },
             new Employee
            {
                Id = 3, Name = "Dinesh Beniwal", City = "New Delhi", Address = "Noida"
            },
            new Employee
            {
                Id = 4, Name = "Dhananjay Kumar", City = "New Delhi", Address = "Delhi"
            },
            new Employee
            {
                Id = 5, Name = "Jitendra Gund", City = "Pune", Address = "Pune"
            },
                   new Employee
            {
                Id = 6, Name = "Anil Kumar", City = "chandigarh", Address = "chandigarh"
            },
            new Employee
            {
                Id = 7, Name = "Ramesh", City = "Mumbai", Address = "Kurla"
            },
            new Employee
            {
                Id = 8, Name = "塗一", City = "北京市", Address = "東城區學城路"
            },
            new Employee
            {
                Id = 9, Name = "江六", City = "北京市", Address = "西城區西長安街"
            },
            new Employee
            {
                Id = 10, Name = "黃七", City = "北京市", Address = "昌平區大學城路"
            },
            new Employee
            {
                Id = 11, Name = "孫八", City = "上海市", Address = "徐家匯區延安西路"
            },
            new Employee
            {
                Id = 12, Name = "Sudhir Wadje", City = "Mumbai", Address = "Kurla"
            },
             new Employee
            {
                Id = 13, Name = "Dinesh Beniwal", City = "New Delhi", Address = "Noida"
            },
               new Employee
            {
                Id = 14, Name = "Dhananjay Kumar", City = "New Delhi", Address = "Delhi"
            },
                 new Employee
            {
                Id = 15, Name = "Jitendra Gund", City = "Pune", Address = "Pune"
            },
                   new Employee
            {
                Id = 16, Name = "Anil Kumar", City = "chandigarh", Address = "chandigarh"
            },
                     new Employee
            {
                Id = 17, Name = "Ramesh", City = "Mumbai", Address = "Kurla"
            },
                       new Employee
            {
                Id = 18, Name = "趙二", City = "深圳市", Address = "羅湖區沿河北路"
            },
                                    new Employee
            {
                Id = 19, Name = "張三", City = "深圳市", Address = "南山區科苑南路"
            },
                                                 new Employee
            {
                Id = 20, Name = "李四", City = "深圳市", Address = "南山區後海大道"
            },
           new Employee
            {
                Id = 21, Name = "Vithal Wadje", City = "Latur", Address = "Kabansangvi"
            },
            new Employee
            {
                Id = 22, Name = "Sudhir Wadje", City = "Mumbai", Address = "Kurla"
            },
             new Employee
            {
                Id = 23, Name = "Dinesh Beniwal", City = "New Delhi", Address = "Noida"
            },
            new Employee
            {
                Id = 24, Name = "Dhananjay Kumar", City = "New Delhi", Address = "Delhi"
            },
            new Employee
            {
            Id = 25, Name = "Jitendra Gund", City = "Pune", Address = "Pune"
            },
            new Employee
            {
                Id = 26, Name = "Anil Kumar", City = "chandigarh", Address = "chandigarh"
            },
            new Employee
            {
                Id = 27, Name = "Ramesh", City = "Mumbai", Address = "Kurla"
            },
             new Employee
            {
                Id = 28, Name = "劉傑", City = "深圳市", Address = "福田區福中路"
            },
            new Employee
            {
                Id = 29, Name = "徐達", City = "深圳市", Address = "羅湖區愛國路"
            },
            new Employee
            {
                Id = 30, Name = "王五", City = "深圳市", Address = "羅湖區人民路"
            },

        };
            //return Json    
            return Json(ObjEmp, JsonRequestBehavior.AllowGet);
        }
    }
}

  Employee.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PagingSoringInMVC.Models
{
    public class Employee
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string City { get; set; }
        public string Address { get; set; }
    }
}

  


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 寫這篇沒有參考任何文章,只是寫下自己一路使用的體會 linux與windows給我的感覺有點像flask之於django.linux只有一個小而強大的內核,各種應用軟體配置自由,就連桌面也有不同的可供選擇。 linux的歷史就不介紹了,百度都有。說一下各個發行版。發行版之間的區別說白了就是軟體的搭配 ...
  • 1. 備份原來的yum源 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2. 下載新的CentOS-Base.repo 到/etc/yum.repos.d/ wget -O /etc/yum ...
  • 第1章 Zabbix簡介及組成 1.1 zabbix簡介 zabbix是一個基於web界面,提供分散式系統監視以及網路監視功能的企業級的開源解決方案。它可以監視各種網路參數,保證伺服器自動的安全運營,並提供靈活的通知機制以讓系統管理員快速定位/解決存在的各種問題 1.1 zabbix組成 zabbi ...
  • 0 操作成功完成.1 功能錯誤.2 系統找不到指定的文件.3 系統找不到指定的路徑.4 系統無法打開文件.5 拒絕訪問.6 句柄無效.7 存儲控制塊被損壞.8 存儲空間不足, 無法處理此命令.9 存儲控制塊地址無效.10 環境錯誤.11 試圖載入格式錯誤的程式.12 訪問碼無效.13 數據無效.14 ...
  • ...
  • 一、安裝mutt 二、配置mutt vim /etc/Muttrc 在裡面找到下麵幾行,並將內容修改為你自己的內容(下麵幾行分佈在不同位置,請耐心查找,記得去掉它行首的#號) 三、下載並解壓msmtp 根據系統情況,需要安裝wget和bzip2 1 yum install wget bzip2 -y ...
  • 我們知道運維工程師(Operations)最基本的職責就是負責服務的穩定性並確保整個服務的高可用性,同時不斷優化系統架構、提升部署效率、優化資源利用率,確保服務可以7 24H不間斷地為用戶提供服務。 如果你想從事Linux運維相關工作,那麼你可以來實驗樓,因為實驗上有: "【Linux運維技術路徑】 ...
  • 要使用Linux系統很重要的一個操作就是使Linux系統能夠訪問互聯網,只有Linux系統能夠訪問互聯網才能夠去下載很多自己所需要的資源,如果不能訪問互聯網那麼使用Linux系統往往會卡在這一步,假設你裝的是一個minimal版本的CentOS,那麼很多Linux系統下麵的工具都是沒有被安裝的,這個 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...