I am using Jquery Datatables plugin. I am showing list of employee details with an provision to edit using the above plugin. My questioon is
Is it possible to set href property of the edit link dynamically along with razor syntax of MVC ?
If not what is the alternate solution to navigate to edit page ?
HTML markup is
table = $("#dataTableMenuRole").dataTable({
"ajax": {
"url": "@Url.Action("LoadGridView", "MenuSettings")",
"method": "POST",
"dataType": "json",
"data": function (d) {
d.roleId = $("#ddlRoles").val()
}
},
columns: [
{ "data": "MenuName" },
{ "data": "CanAdd" },
{ "data": "CanEdit" },
{ "data": "CanDelete" },
{ "data": "CanView" },
{ "data": "MenuRoleId" }
],
"bProcessing": true,
"aoColumnDefs": [{
"targets": 5,
"bSortable": false,
"render": function (data, type, full, meta) {
return '<a class="btn btn-info"
href="@Url.Action("Edit", new {id= data })"' >'+
//Here data cannot be assigned as shown
'<i class="fa fa-edit"></i>'+
'</a>'
}
}]
});
You need to render an HTML link like this (apologies for any quote errors!):
The
full
parameter is the full datasource for the current row, so assumingMenuRoleId
is the Id you want to use, you access it usingfull[5]
You could use Razor syntax to create the url, but it means that the datatables javascript code would need to be in View, which is not ideal.