Adding EDIT button in DATATABLE (MVC ASP.NET CORE) not working HTML ACTION
Adding EDIT button in DATATABLE (MVC ASP.NET CORE) not working HTML ACTION
DataTableGuy10
Posts: 6Questions: 2Answers: 0
Hey guys, how are you?
I need help, i was not able to CREATE the EDIT button to my DATATABLE; i am filling each row using a FOREACH,
I can't use the Html.ActionLink helper because i have to generate the links dynamically from the javascript
This is my code:
@model IEnumerable<WebApplication.Models.Approval>
@{
ViewData["Title"] = "Approvals";
}
<h1>Approvals</h1>
<table class="table" id="Exampledatatable">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.CODE)
</th>
<th>
@Html.DisplayNameFor(model => model.EMAIL)
</th>
<th>
@Html.DisplayNameFor(model => model.FIRSTNAME)
</th>
<th>
@Html.DisplayNameFor(model => model.LASTNAME)
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.CODE)
</td>
<td>
@Html.DisplayFor(modelItem => item.EMAIL)
</td>
<td>
@Html.DisplayFor(modelItem => item.FIRSTNAME)
</td>
<td>
@Html.DisplayFor(modelItem => item.LASTNAME)
</td>
<td>
@Html.ActionLink("EDIT", "Edit", new { id = item.code })
</td>
</tr>
}
</tbody>
</table>
I need to replace this:
<td>
@Html.ActionLink("EDIT", "Edit", new { id = item.code })
</td>
I was thinking about creating something like this:
<script type="text/javascript">
$(document).ready(function () {
$('#myDataTable').dataTable({
aoColumns: [
null, // first column (CODE)
null, // second column (EMIAL)
null, // third (FIRSTNAME)
null, // fourth (LASTNAME)
{ // fifth column (Edit link)
"sName": "CODE",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj)
{
// oObj.aData[0] returns the CODE
return "<a href='/Edit?id="
+ oObj.aData[0] + "'>Edit</a>";
}
}
]
});
});
</script>
Can help me to create my SCRIPT to make it work, i'm super lost
This discussion has been closed.
Replies
Is this using Editor buttons? Or some other method?
Colin
Duplicate of this thread - please don't repost as it wastes people's time...
Colin
Hey Colin, yeah... i'm sorry, i just wanted to create a new question (my previous one has some typing errors). What do you mean by "Editor BUTTONS"?. The problem in my code is that i do not understand how to "add" the HTML ACTION LINK to the JS Script itself, otherwise i wont be able to edit every row of the datatable, do you get me?