8

我正在 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 中的当前行或项目以使其工作?

非常感谢任何帮助。

问候

詹姆士

4

2 回答 2

11
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>
于 2011-08-01T06:34:23.577 回答
4

也可以使用下面这更像是正常的方式,所以我更喜欢它:

grid.Column(format: @<text>
                @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
                @Html.ActionLink("Delete", "Delete", new { id = item.Id })    
     </text>)
于 2012-02-21T15:54:48.650 回答