2012-02-18 77 views
4

我正在使用WebGrid幫助程序在我的MVC應用程序中對網格進行排序。如何在MVC3中將WebGrid添加列

@{ 
     var grid = new WebGrid(Model, canSort:true); 
     @grid.GetHtml(columns:grid.Columns(

       grid.Column("Username", "Full Name", canSort:true), 
       grid.Column("Profile","Profile", canSort:false) 
      )); 
    }  

排序的列將覆蓋(顯示鏈接)默認標題的風格我該怎麼維護?

在最後一欄我有圖像行動,這將使用JavaScript對話框

<img title="View Detail" style="cursor: pointer" onclick="openPopup('@item.EncryUserId')" 
          src="@Url.Content("~/Content/Images/view-fullscreen.png")" /> 

我如何可以添加使用的WebGrid這個附加列打開彈出?

謝謝。

回答

4

最後我得到了答案,因爲按照以下

grid.Column(header: "Details", 
       format: @<text><img src="@Url.Content("~/Content/Images/view-fullscreen.png")" 
       style="cursor: pointer" onclick="openPopup('@item.EncryUserId')"                   
       alt="View Detail" title="View Detail"/></text>) 

和內部頭有錨標記,所以我增加了headerStyle:「tdheader」 ,並添加新的風格.tdheader一個{顏色:white};

1
grid.Column(format: 
    @<img title="View Detail" style="cursor: pointer" onclick="openPopup('@item.EncryUserId')" src="@Url.Content("~/Content/Images/view-fullscreen.png")" /> 
) 
+0

感謝您的幫助,但是您錯過了@text,它負責在(@)代碼部分中包含html。 – 2012-02-18 12:27:32