How to put additional column to WebGrid in MVC3

2019-05-08 22:04发布

问题:

I am using WebGrid helper to make grid sortable in my MVC application.

@{
        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)
            ));
   }       

Sortable column will override(display blue link) default style of header how can I maintain that?

In last column I have image action which will open popup using javascript dialog

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

How can I add this additional column using WebGrid?

Thanks.

回答1:

Finally I got answer as per below

   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>) 

and inside header there is anchor tag so i have added headerStyle: "tdheader" and add new style .tdheader a{ color: white};



回答2:

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