Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在ActionLink中调用删除前确认消息,然后调用控制器进行删除_Javascript_Asp.net Mvc_Actionlink - Fatal编程技术网

Javascript 如何在ActionLink中调用删除前确认消息,然后调用控制器进行删除

Javascript 如何在ActionLink中调用删除前确认消息,然后调用控制器进行删除,javascript,asp.net-mvc,actionlink,Javascript,Asp.net Mvc,Actionlink,下面是我的Webgrid专栏“操作”,我在其中放置了编辑和删除选项。我想在去控制器之前给你一个确认信息。下面是不适合我的代码 grid.Column(header: "Actions", format: (item) => new HtmlString( Html.ActionLink("Edit", "GetEditRecord", new { id = item.id }, new {@class = "ActionEdit"}).ToSt

下面是我的Webgrid专栏“操作”,我在其中放置了编辑和删除选项。我想在去控制器之前给你一个确认信息。下面是不适合我的代码

 grid.Column(header: "Actions", format: (item) =>
           new HtmlString(
           Html.ActionLink("Edit", "GetEditRecord", new { id = item.id }, new {@class = "ActionEdit"}).ToString()  +
                           Html.ActionLink("Delete", "Delete", new { id = item.id }, new {@class = "ActionDelete", OnClientClick="test();"} ) .ToString()
                               ))
下面是Javascript函数

<script language="javascript">
function test() {
    alert("Hello\nHow are you?");
    //changeasset.class = "cd-panel from-right AddAssetForm is-visible";
}
    </script>

功能测试(){
警报(“你好\n你好吗?”);
//changeasset.class=“右AddAssetForm中的cd面板可见”;
}
请帮助。

使用此功能

function test(){
     confirm('do you want to delete this');
}

我将在客户端代码中绑定侦听器,而不是尝试将ActionLink中的click事件侦听器与“OnClientClick”绑定

var deleteLinks = document.querySelectorAll('.ActionDelete');

Array.prototype.forEach.call(deleteLinks, function(link){
   link.addEventListener('click', test, false);
});

再次不调用上述函数