c# - How do you make an MVC Webgrid show multiple lines in a cell? -
i have function in code generates string a\nb\nc, when pulled webgrid, use function on razor side change \n <br />, , know works because in webpage source shows string on 3 separate lines.
@functions { public static string replacelinebreaks(string s) { return s.replace(environment.newline, "@html.raw(<br />)"); } }
<div id="grid_mywebgrid"> @grid.gethtml( tablestyle : "table", alternatingrowstyle : "alternate", headerstyle : "header", columns: grid.columns( grid.column("letters", format: item => @html.raw(replacelinebreaks(html.encode(item.letters)))), ) ) </div>
but when load page, cell column shows:
abc
instead of:
a b c
is there in webgrid lets tell that column used multi-line cell?
i found called @helper can use design razor inline templates. using @helper, wrote foreach statement create spans each of strings.
@helper displaymultiline(string str) { foreach(string s in str.split(new char[] {'\n'})) { @s <br /> } }
<div id="grid_searchentities"> @grid.gethtml( tablestyle : "table", alternatingrowstyle : "alternate", headerstyle : "header", columns: grid.columns( grid.column("letters", format:@<text>@displaymultiline(@item.letters)</text>), ) ) </div>
Comments
Post a Comment