Search code examples
asp.net-mvc-3jqgridhtml.actionlink

Add ActionLink in JqGrid column in ASP.NET MVC 3 Razor


I am using jqGrid with ASP.NET MVC 3 and Razor.

I am looking to add 2 columns to the jqGrid along with the rest of the columns.

The columns I want to add are

  • Edit
  • Delete

These columns value I want to be ActionLink.

How do I add an ActionLink to a Column of a JqGrid ?

Please guide me on this.

Update 1: with help from @user1534482 I tried this but did not work

colModel: [
    ...
    { name: 'Open', formatter: 'prepareLinks' },
    ...
],

 function prepareLinks(cellvalue, options, rowObject) {
    return "@Html.ActionLink("Open this","Test")";

}

javascript error message :

SyntaxError: missing ; before statement
[Break On This Error]   

return "<a href="/SomeController/Test">Open this</a>";

SomeController (line 92, col 41)

Solution

  • Thanks to @tpeczek and @user1534482

    I finally got the solution,

    colModel: [
        ...
        { name: 'Open',
            formatter: function (cellvalue, options, rowObject) {
                return '<a href="/ControllerName/Test/?myId=' + cellvalue + '">' + "Open" + '</a>';
            } 
        },
        ...
    ],