Is it possible to conditionally set a CSS class or encode a string to html for a certain web grid column? I was able to append span tags to the item using format: in the column, but now I need to add a class to the span tags based on a helper function in razor view or a bool expression from the controller/model. I do not want to do this with JS, C# should suffice.
Here is what I tried in view model:
@grid.GetHtml(
headerStyle:"reviewGridHeader",
columns: grid.Columns(
...[other columns]...
grid.Column(columnName: "FeedBack", format: @<span>@CheckFeedBack(item.FeedBack)</span>)
))
Helper function in view model (splits and compares string):
static string CheckFeedBack(string item) {
String[] feedbacks = System.Text.RegularExpressions.Regex.Split(item, "of");
//if feedback complete
if((Convert.ToInt32(feedbacks[0]) == (Convert.ToInt32(feedbacks[1]))))
{
string newFeedback = @"<span class=""feedBackComplete"">"+ item +"</span>";
string encodedFeedback = System.Web.HttpUtility.HtmlEncode(newFeedback);
return encodedFeedback;
}
return item;
}
And here is the presentation, which conditionally works when feedback complete:

Update: After guidance from Zach with returning a MvcHtmlString, I had some problems being able to use this helper method above in a WebGrid Column. Below shows the correct syntax:
grid.Column(columnName: "FeedBack", format: (item) => CheckFeedBack(item.FeedBack), style: "webGridAlignment")
You must return the html not a string… for that case you can use MvcHtmlString and just raw in the view