WebGrid ActionLink how to get row object

I have WebGrid which is build using Model I build it using code below:


@model IEnumerable<ExampleMVC4.Models.LicenseInfo>
    ViewBag.Title = "Licenses";
    WebGrid grid = new WebGrid(Model);    
@grid.GetHtml(tableStyle: "table table-striped table-hover",
  columns: new[] {
    grid.Column(header: "IsValid", format: item=>new HtmlString(Html.ActionLink((string)item.IsValid.ToString(), "Deactivate", new { @id =  item.SerialNumber} ).ToString()))


public ActionResult Index()
    var data = getLicenseInfoList();
    return View(data);

public ActionResult Deactivate(string serialNum_)
    if (serialNum_ != null)
        ViewBag.Message = serialNum_;
    return View();

But I am unable to get it to call Deactivate() function with serial number.

What is the proper way to handle ActionLink click inside WebGrid?


Your ActionLink is generating a route parameter named id ( ... new { @id = item.SerialNumber} .. but you methods parameter name is serialNum_. Change the methods signature to

public ActionResult Deactivate(string id)

Note also its a link so its a GET, not a POST (although its not clear what the method does)

Need Your Help

Char to int implicit cast Behind the Scenes

c# operators implicit-conversion

The following is valid in c# as Char can be implicitly cast to int

Customising Icon for Google Maps Markers

javascript jquery google-maps google-maps-api-3

I am getting a ;'Uncaught Syntax Error: Unexpected identifier' at line 28 when trying to change the icon for a set of markers. The markers are part of a loop but I cant see why it should be an issu...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.