Cannot create EDIT button on DATATABLE (using MVC ASP.NET CORE) HTML ACTION
Cannot create EDIT button on DATATABLE (using MVC ASP.NET CORE) 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.
Answers
Please don't post duplicate questions. This is your third thread with the same questions. Did you see my answer in your other thread?
Kevin
Hey Kevin, i just make a different one because my original question was not very clear. I tried what you told me but it did not work.
In the future please just update the original thread. Its less confusing for those trying to help.
What exactly is not working?
Do you get errors in the browser's console or alert messages?
Can you post a link to your page or a test case showing the issue?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Do not really know how to create the JS script based on my HTML file. I'm kinda lost