av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

ASP.NETMVC3Beta初體驗(yàn)之WebGrid

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

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

我通過(guò)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","單價(jià)"),               
  13. grid.Column("UnitsInStock", "庫(kù)存單位"),               
  14. grid.Column("UnitsOnOrder","訂單單位"),               
  15. grid.Column("ReorderLevel","重新排序級(jí)別"),               
  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","單價(jià)"),  
  17. grid.Column("UnitsInStock", "庫(kù)存單位"),  
  18. grid.Column("UnitsOnOrder","訂單單位"),  
  19. grid.Column("ReorderLevel","重新排序級(jí)別"),  
  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.  

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

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

2、columnNames表示顯示的列

3、defaultSort 默認(rèn)按什么排序

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

5、canPage 是否能排序

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

運(yùn)行:

在看看兩個(gè)view的完整代碼:

aspx:

 
 
 
 
  1. <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage>" %> 
  2.       
  3. 產(chǎn)品列表  
  4.  
  5.     
  6. function deleteRecord(a, b) {          
  7. alert("刪除:"+b);     
  8.  } 
  9.  

    產(chǎn)品列表

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

 

Razor去掉了那些模板頁(yè)的代碼,使代碼看起來(lái)更整潔。比較喜歡Razor。

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

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


分享題目:ASP.NETMVC3Beta初體驗(yàn)之WebGrid
當(dāng)前地址:http://uogjgqi.cn/article/dppdsgc.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流

其他資訊