2012-02-18 71 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