8

I'm developing a web application using MVC3 in VB.NET.

I having difficulty setting a column on the webgrid with the following action links

Edit | Details | Delete

@*@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})*@

I have tried to use syntax below but I get an error where item is not declared.

grid.Column(header:= "",format:= (item) => item.GetSelectLink("Custom Text"))

How do I reference the current row or item in a webgrid to make this work?

Any help greatly appreciated.

Regards

James

Ahmad
  • 22,657
  • 9
  • 52
  • 84
winsql
  • 731
  • 1
  • 8
  • 17

2 Answers2

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);

}),

renders the following HTML (formatted for legibility)

<td>
  <a href="/Home/Edit/5">Edit</a> | 
  <a href="/Home/Details/5">Details</a> | 
  <a href="/Home/Delete/5">Delete</a>
</td>
Ahmad
  • 22,657
  • 9
  • 52
  • 84
  • 1
    Hi Ahmad Many thanks for the reply. I'll modify this for VB.NET and give a try. Where is "(item)" declared? – winsql Aug 03 '11 at 22:16
  • @winsql - refer to http://msdn.microsoft.com/en-us/library/system.web.helpers.webgridcolumn.format(v=vs.99).aspx – Ahmad Aug 04 '11 at 06:30
4

Can also use the below which is more like the normal way so I like it better:

grid.Column(format: @<text>
                @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
                @Html.ActionLink("Delete", "Delete", new { id = item.Id })    
     </text>)
pbb
  • 151
  • 1
  • 2