2016-11-01 56 views
0

如何添加jQuery數據表到這個mvc頁面來實現過濾器?我不知道使用哪些參數來初始化dataTable以使用模型中的數據,以及如何在搜索網格上進行關鍵字搜索。添加jQuery數據過濾器到mvc.net頁面

<p> 
@Html.ActionLink("Create New", "LandingCreate") 
</p> 
<table class="table" id="contentTable"> 
<tr> 
    <th> 
     @Html.DisplayNameFor(model => model.URL) 
    </th> 
    <th> 
     @Html.DisplayNameFor(model => model.HTMLText) 
    </th> 
    <th></th> 
</tr> 

@foreach (var item in Model) { 
<tr> 
    <td> 
     @Html.DisplayFor(modelItem => item.URL) 
    </td> 
    <td> 
     @Html.DisplayFor(modelItem => item.HTMLText) 
    </td> 
    <td> 
     @Html.ActionLink("Edit", "LandingEdit", new { id = item.Id }) | 
     @Html.ActionLink("Delete","LandingDelete", 
     new { id = item.Id }, 
     new { onclick = "return confirm('Are you sure you wish to delete this page?');" }) 

    </td> 
</tr> 
} 
    </table> 

編輯 這是我的腳本部分:

@section Scripts 
{ 
<script> 
    var settings = { 
      baseParameters: { 
       itemsPerPage: pageSettingStorage.defaultItemsPerPage, 
       hideColumns: [] 
      }, 
      parameters: { 
       start: 0, 
       search: '', 
       firstDate: firstDate, 
       lastDate: lastDate, 
       status: 'new', 
       order: [[0, "asc"]], 
      } 
    }; 
    $(document).ready(function() { 
     $("#contentTable").DataTable({ 
      paging: false, 
      "ajax": { 
       "url": "/Admin/LoadLanding", 
       "type": "GET", 
       "datatype":"json" 
      }, 
      "columns": { 
       "data": "URL", 
       "data":"HTMLText" 
      } 
     }); 
    }); 

LoadLanding方法

public ActionResult LoadLanding() 
    { 
     var model = RepositoryManager.Instanse.LandingContentRepository.SelectAll(); 
     return Json(new { data = model }, JsonRequestBehavior.AllowGet); 
    } 
+0

@ Dean.DePue完成了它 –

回答

0

改變返回到這一點:

public ActionResult LoadLanding() 
{ 
    var model = RepositoryManager.Instanse.LandingContentRepository.SelectAll(); 
    return Json(new { aaData = model.Select(x => new String[] { 
x.URL, 
x.HTMLText 
    })}, JsonRequestBehavior.AllowGet); 
} 
相關問題