Reputation: 3046
I have to display if the Grid column value is "true" then "Yes" else "No". Tried in WebGrid
but throwing me error in the GridColumn
in View.
//Code:
grid.Column("SelectedStatus", header: "Selected Status", Model.SelectedStatus==true ? Html.Raw("Yes"): Html.Raw("No"))
When i tried to use format:
in the column it is throwing me "Invalid arguments"
error.
Where i'm wrong?
Upvotes: 0
Views: 2788
Reputation: 78565
A few things. Firstly the error message which is fairly obvious - you understood that you needed to add a named argument at the end because fixed arguments cannot appear after named arguments.
Second, the format parameter is not a string but rather of expects a type System.Func<Object, Object>
so you can replace it with:
grid.Column("SelectedStatus", "Selected Status", m => m.SelectedStatus == true ? Html.Raw("Yes") : Html.Raw("No"))
You'll notice I removed the named header
parameter too, because it's already the second argument in the list anyway so it is redundant here.
Finally, if Model.SelectedStatus
is a bool
(rather than a bool?
) there is no need for the == true
. You can simply write:
m => Html.Raw(m.SelectedStatus ? "Yes" : "No")
Upvotes: 1