0

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?

A Coder
  • 3,039
  • 7
  • 58
  • 129

1 Answers1

1

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

WebGrid.Column Docs

CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176
  • Oops!!!. Comment removed. Its fine now. One question is how the lamda expression 'm' getting assigned to the Model? – A Coder May 06 '14 at 13:32
  • Can you look into this? http://stackoverflow.com/questions/23366843/cannot-convert-from-lambda-expression-to-system-func-dynamic-object-mvc3-ra – A Coder May 06 '14 at 13:34