There is a timing issue here...You can do some work around but I have to ask, why?
Why not to put the formatting int the view? are you want to use dynamic models with the same view?
In any case - even with my solution you still will have the problem of the html content GetEditButtons returns - this content will be encoded and displayed as such and not as real html...
List<webgridcolumn> columnSet = new List<webgridcolumn>() {col1, col2, col3, col4, col5, col6};
ViewBag.GridCols = columnSet;</webgridcolumn></webgridcolumn>
@grid.GetHtml(
tableStyle : "table",
alternatingRowStyle : "alternate",
selectedRowStyle: "selected",
headerStyle : "header",
columns : ViewBag.GridCols
)
It will call your method, but the html content returned by it will not create real html, but will be encoded...
If you insist on creating column in the controller you better make an extension function instead of GetHtml and make you changes there
http://stackoverflow.com/questions/11698665/mvc3-web-grid-adding-action-links-at-the-begining-of-columns-list[
^]
It is also better to use ActionLink helper method to create clickable links (like edit/delete) instead of creating html content like you did...