Categories
Uncategorized

Check Box in Webgrid MVC 3

Below is a simple demonstration on how to use checkbox inside a webgrid column in MVC 3.

I had a field called ‘HasPassport’ in my model which was of type **boolean **for which I required a checkbox column, to show a checked checkbox for every true value and an unchecked checkbox otherwise.

Using the WebGrid.Column’s format parameter below is how I have used…

grid.Column(  
header: "HasPassport ?",
format:
(col) => @Html.Raw(
"<input type='checkbox' checked='" +
((col.HasPassport) ? "checked" : "") +
"' disabled='true' />")  
)
So for every true value for the 'hasPassport' field the following HTML code is generated :
<input type='checkbox' checked='checked' disabled='true' />
Hope this helps ! Cheers !