I have been searching for the last few hours, and unfortunately I cannot seem to find an example of how to populate a datatable with an action edit and delete link column using .net and MVC.
Here is what I have so far, how do I add an action link? What am I missing?
<script type="text/javascript">
$(document).ready(function () {
$('#myDataTable').dataTable({
bProcessing: true,
sAjaxSource: '@Url.Action("Index1", "Default1")'
});
});
</script>
<div id="container">
<div id="demo">
<table id="myDataTable">
<thead>
<tr>
<th>
RoleId
</th>
<th>
RoleName
</th>
<th>
UserId
</th>
<th>
UserName
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
I want to add this in the last column;
<td>
@Html.ActionLink("Edit", "Edit", new {id=item.PrimaryKey}) |
@Html.ActionLink("Details", "Details", new { id=item.PrimaryKey }) |
@Html.ActionLink("Delete", "Delete", new { id=item.PrimaryKey })
</td>
But cannot figure out how to do it.
You could use the
aoColumnsproperty withfnRenderfunction to add custom columns.You can’t use the
Html.ActionLinkhelper because you have to generate the links dynamically from the javascript. TheaoColumnsproperty helps you to configure each columns, if you don’t want to configure a particular column just passnullelse you have to pass anobject({}).The
fnRenderfunction helps you to create the links using the values of the other columns. You can use theoObj.aDatato get the values of the other column likeidto generate the links.Another important thing in the JSON output you return from the server, for the edit column also you have to return something like 1, 2, 3 or anything.
Reference: http://jquery-datatables-editable.googlecode.com/svn/trunk/ajax-inlinebuttons.html