문제

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top