Asp.net-Mvc-3
列中的 MVC3 WebGrid 自定義文本
我正在 VB.NET 中使用 MVC3 開發一個 Web 應用程序。
我很難使用以下操作連結在 webgrid 上設置列
編輯 | 詳情 | 刪除
@*@Html.ActionLink("Edit", "Edit", New With {.id = currentItem.PrimaryKey}) | @Html.ActionLink("Details", "Details", New With {.id = currentItem.PrimaryKey}) | @Html.ActionLink("Delete", "Delete", New With {.id = currentItem.PrimaryKey})*@我嘗試使用下面的語法,但在未聲明 item 的地方出現錯誤。
grid.Column(header:= “",format:= (item) => item.GetSelectLink(“Custom Text”))
如何引用 webgrid 中的目前行或項目以使其工作?
非常感謝任何幫助。
問候
詹姆士
grid.Column( columnName:"PrimaryKey", header:"Actions", format: (item) => { var links = Html.ActionLink("Edit", "Edit", new {id = item.PrimaryKey}) + " | " + Html.ActionLink("Details","Details", new { id = item.PrimaryKey}) +" | "+ Html.ActionLink("Delete","Delete", new { id = item.PrimaryKey}); return Html.Raw(links); }),呈現以下 HTML(為易讀而格式化)
<td> <a href="/Home/Edit/5">Edit</a> | <a href="/Home/Details/5">Details</a> | <a href="/Home/Delete/5">Delete</a> </td>
也可以使用下面這更像是正常的方式,所以我更喜歡它:
grid.Column(format: @<text> @Html.ActionLink("Edit", "Edit", new { id = item.Id }) | @Html.ActionLink("Delete", "Delete", new { id = item.Id }) </text>)