日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
ASP.NETMVC3Beta初體驗之WebGrid

ASP.NET MVC 3 Beta中除了推出一種新的視圖引擎Razor。還推出了幾種新的HtmlHelper。我比較關(guān)注的是WebGrid,這篇文章將介紹一下WebGrid的使用。WebGrid提供了分頁和排序的功能,在此之前在MVC中分頁和排序時需要自己去寫的。這篇文章將分別介紹在aspx視圖引擎和Razor視圖引擎中如何使用它。

在西華等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供做網(wǎng)站、網(wǎng)站設(shè)計 網(wǎng)站設(shè)計制作定制網(wǎng)站,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計,營銷型網(wǎng)站,外貿(mào)網(wǎng)站制作,西華網(wǎng)站建設(shè)費用合理。

我通過ADO.NET Entity Data Model從NORTHWND的Products中表中取數(shù)據(jù)。在Controller中取數(shù)據(jù):

 
 
 
 
  1. public class HomeController : Controller      
  2. {        public ActionResult Index()         
  3.  {             
  4.  NORTHWNDEntities entity = new NORTHWNDEntities();              
  5. return View( entity.Products.ToList());        
  6.   }     }  

在aspx視圖引擎中使用WebGrid代碼如下:

 
 
 
 
  1.     
  2. <% var grid = new WebGrid(source: Model, defaultSort: "ProductName", rowsPerPage: 5); %>   
  3. <%=grid.GetHtml(       
  4. tableStyle: "grid",       
  5. headerStyle: "head",       
  6. alternatingRowStyle: "alt",       
  7. columns: grid.Columns(                 
  8. grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.ProductID })),                 
  9. grid.Column(format: (item) => Html.ActionLink("Delete", "Delete", null, new { onclick = string.Format("deleteRecord('Employee', '{0}')", item.ProductID), @class = "Delete", href = "JavaScript:void(0)" })),                 
  10. grid.Column("ProductName","產(chǎn)品名稱"),               
  11. grid.Column("QuantityPerUnit","每單位數(shù)量"),                 
  12. grid.Column("UnitPrice","單價"),               
  13. grid.Column("UnitsInStock", "庫存單位"),               
  14. grid.Column("UnitsOnOrder","訂單單位"),               
  15. grid.Column("ReorderLevel","重新排序級別"),               
  16. grid.Column("Discontinued","已停產(chǎn)")     )     )    %>
  17.  
 

在Razor中使用WebGrid代碼如下:

 
 
 
 
  1.   
  2. @{    
  3. var grid = new WebGrid(source: Model,  
  4. defaultSort: "ProductName",   
  5. rowsPerPage: 10);  
  6. }  
  7. @grid.GetHtml(  
  8. tableStyle: "grid",  
  9. headerStyle: "head",  
  10. alternatingRowStyle: "alt",  
  11. columns: grid.Columns(  
  12. grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.ProductID })),  
  13. grid.Column(format: (item) => Html.ActionLink("Delete", "Delete", null, new { onclick = string.Format("deleteRecord('Product', '{0}')", item.ProductID), @class = "Delete", href = "JavaScript:void(0)" })),   
  14. grid.Column("ProductName","產(chǎn)品名稱"),  
  15. grid.Column("QuantityPerUnit","每單位數(shù)量")  
  16. ,grid.Column("UnitPrice","單價"),  
  17. grid.Column("UnitsInStock", "庫存單位"),  
  18. grid.Column("UnitsOnOrder","訂單單位"),  
  19. grid.Column("ReorderLevel","重新排序級別"),  
  20. grid.Column("Discontinued","已停產(chǎn)")))
 

WebGrid構(gòu)造函數(shù)如下:

 
 
 
 
  1. public WebGrid(IEnumerable source, 
  2. IEnumerable columnNames = null, 
  3. string defaultSort = null, 
  4. int rowsPerPage = 10, 
  5. bool canPage = true, bool canSort = true, 
  6. string ajaxUpdateContainerId = null, 
  7. string fieldNamePrefix = null, 
  8. string pageFieldName = null, 
  9. string selectionFieldName = null, 
  10. string sortFieldName = null, 
  11. string sortDirectionFieldName = null);  
  12.  

常見參數(shù)意思是:

1、source 表示數(shù)據(jù)源

2、columnNames表示顯示的列

3、defaultSort 默認按什么排序

4、rowsPerPage 每頁多少行數(shù)據(jù)

5、canPage 是否能排序

上面兩段代碼的意思是定義了一個既分頁又能排序的grid。

運行:

在看看兩個view的完整代碼:

aspx:

 
 
 
 
  1. <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage>" %> 
  2.       
  3. 產(chǎn)品列表  
  4.  
  5.  
  6.  

    產(chǎn)品列表

        
  7.    
  8. <% var grid = new WebGrid(source: Model, defaultSort: "ProductName", rowsPerPage: 5); %>   
  9. <%=grid.GetHtml(       
  10. tableStyle: "grid",       
  11. headerStyle: "head",       
  12. alternatingRowStyle: "alt",       
  13. columns: grid.Columns(                
  14.  grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.ProductID })),                 
  15. grid.Column(format: (item) => Html.ActionLink("Delete", "Delete", null, new { onclick = string.Format("deleteRecord('Employee', '{0}')", item.ProductID), @class = "Delete", href = "JavaScript:void(0)" })),                 
  16. grid.Column("ProductName","產(chǎn)品名稱"),               
  17. grid.Column("QuantityPerUnit","每單位數(shù)量"),                 
  18. grid.Column("UnitPrice","單價"),               
  19. grid.Column("UnitsInStock", "庫存單位"),               
  20. grid.Column("UnitsOnOrder","訂單單位"),               
  21. grid.Column("ReorderLevel","重新排序級別"),               
  22. grid.Column("Discontinued","已停產(chǎn)")     )     )    %> 
 

Razor:

代碼 

 
 
 
 
  1.  @model List @{  View.Title = "產(chǎn)品列表"; } 

     

  2. 產(chǎn)品列表

        @{       
  3. var grid = new WebGrid(source: Model,  defaultSort: "ProductName",   rowsPerPage: 3); }  @grid.GetHtml(       
  4. tableStyle: "grid",       
  5. headerStyle: "head",       
  6. alternatingRowStyle: "alt",       
  7. columns: grid.Columns(            
  8. grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.ProductID })),          
  9. grid.Column(format: (item) => Html.ActionLink("Delete", "Delete", null, new { onclick = string.Format("deleteRecord('Product', '{0}')", item.ProductID), @class = "Delete", href = "JavaScript:void(0)" })),             
  10. grid.Column("ProductName","產(chǎn)品名稱"),          
  11. grid.Column("QuantityPerUnit","每單位數(shù)量"),          
  12. grid.Column("UnitPrice","單價"),            
  13. grid.Column("UnitsInStock", "庫存單位"),          
  14. grid.Column("UnitsOnOrder","訂單單位"),          
  15. grid.Column("ReorderLevel","重新排序級別"),          
  16. grid.Column("Discontinued","已停產(chǎn)")     )     )   
 

 

Razor去掉了那些模板頁的代碼,使代碼看起來更整潔。比較喜歡Razor。

總結(jié):本文很簡單,介紹了一下ASP.NET MVC 3 Beta中新功能WebGrid,由于這種方式WebGrid是在內(nèi)存中分頁和排序的,所以不適合大數(shù)據(jù)量。

源碼下載地址:http://down./data/134994


本文名稱:ASP.NETMVC3Beta初體驗之WebGrid
文章分享:http://m.5511xx.com/article/dppdsgc.html