Jquery Datatable - 可以动态地将链接的href属性与剃刀语法绑定 [英] Jquery Datatable -Is it possible to bind href property of link with razor syntax dynamically

查看:272
本文介绍了Jquery Datatable - 可以动态地将链接的href属性与剃刀语法绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Jquery Datatables 插件。我显示员工详细信息列表,并使用上述插件进行编辑。我的questioon是

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

是否可以动态地设置编辑链接的href属性以及MVC的剃刀语法?

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标记

        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>'
            }

        }]

    });


推荐答案

您需要渲染这样的HTML链接(道歉对于任何报价错误!):

You need to render an HTML link like this (apologies for any quote errors!):

return '<a class="btn btn-info" href="/Edit/' + full[5] + '"><i class="fa fa-edit"></i></a>';

full 参数是完整的数据源当前行,所以假设 MenuRoleId 是要使用的Id,您可以使用 full [5]

The full parameter is the full datasource for the current row, so assuming MenuRoleId is the Id you want to use, you access it using full[5]

您可以使用Razor语法创建url,但这意味着数据表JavaScript代码将需要在View中,这不是理想的。

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.

这篇关于Jquery Datatable - 可以动态地将链接的href属性与剃刀语法绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆