Formatting text in cell

Apr 9, 2014 at 8:51 AM
I need to highlight specific words in the text in a cell. I'm using a helper function to place the text in div tags to set the height, this works perfect. I then replace the word I want to highlight with the word surrounded by span tags. For some reason the div tags works perfect but the span tags gets rendered as text.

code to add column in grid
columns.Add(c => c.text).Titled("text").Filterable(true).Encoded(false).Sanitized(false).RenderValueAs(o => @CustomRenderingOfColumn(o)).SetWidth(1200);
helper function:
 @helper CustomRenderingOfColumn(analysis3.Models.clipModel t)
     if(t.text.ToString().Length >0 && t.keyword.ToString().Length >0)
         <div style="height:100px;overflow-y:scroll">@t.text.Replace(@t.keyword,"<span style='background:lime'>"+@t.keyword+"</span>")</div>
resulting text:
text text text <span style='background:lime'>keyword</span> text text
I can't understand why some tags render correctly and some are ignored.

Any suggestions please :)

Apr 16, 2014 at 3:03 AM
Edited Apr 16, 2014 at 3:04 AM

I guess you need to raw html (avoid XSS in the keyword property)
@(Html.Raw(t.text.Replace(@t.keyword,"<span style='background:lime'>"+@t.keyword+"</span>")))
Apr 16, 2014 at 12:05 PM
Spot on, thanks Bukharin