如何以编程方式在控制器中创建actionlink并将其传递给webgrid

时间:2015-03-02 04:53:03

标签: asp.net-mvc-4

Dim gridvalue = masobj.fillauditplanDet(cond)
Dim columns As New List(Of WebGridColumn)()
columns.Add(New WebGridColumn() With {.ColumnName = "Year", .Header = "Year"}) columns.Add(New WebGridColumn() With {.ColumnName = "ID", .Header = "", .Format = Function(model) New HtmlString(Html.ActionLink("Edit", "edit", New With {.ID = item.ID}).ToString())}) 
ViewBag.cols = columns 

return PartialView("_WebGrid", gridvalue)

1 个答案:

答案 0 :(得分:0)

最好使用tagBuilder class:

var tb = new TagBuilder("a");
tb.MergeAttribute("href",Url.Action("Edit", "edit", New With {.ID = item.ID}).ToString());
tb.AddCssClass(cssClass);
tb.ToString(TagRenderMode.SelfClosing);


columns.Add(New WebGridColumn() With {.ColumnName = "Year", .Header = "Year"}) columns.Add(New WebGridColumn() With {.ColumnName = "ID", .Header = "", .Format = Function(model) tb.ToString(TagRenderMode)})