我无法在 Jquery 数据表 MVC ASP.NET (C#) 中添加编辑按钮

时间:2021-02-21 22:17:15

标签: javascript jquery asp.net-mvc datatable datatables

需要这方面的帮助,我被卡住了:

我决定使用 jquery 数据表,但我无法创建 EDIT 按钮,我需要转换这个:

<td>
@Html.ActionLink("EDIT", "Edit", new { id = item.code })    
</td>

有人需要帮助修改我的代码吗?

这是我的代码:

@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>


@section scripts{
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.23/af-2.3.5/datatables.min.css" />

    <script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.23/af-2.3.5/datatables.min.js"></script>
    <script>
        $(document).ready(function () {
            $('#Exampledatatable').DataTable({
                

            })
        });
    </script>
}

我一直在搜索,可以使用这样的东西(这只是一个例子):

   "aoColumns": [
          { mData: 'title' } ,
          { mData: 'name' },
          { mData: 'year_name' },
          { 
             mData: '',
             render: (data,type,row) => {
               return `<a href='link_to_edit/${row.id}'>update</a>`;
             }
          }
        ]

可以帮我修改我的代码吗?我超级迷路

0 个答案:

没有答案
相关问题