ASP.NET MVC删除操作链接确认
发布时间:2020-12-30 11:29:13 所属栏目:asp.Net 来源:互联网
导读:td %= Html.ActionLink(Delete, DeleteUser, new RouteValueDictionary(new {uname=item.UserName}), new { onclick = return confirm(Are you sure you want to delete this User?); }) % /td
<td> <%= Html.ActionLink("Delete","DeleteUser",new RouteValueDictionary(new {uname=item.UserName}),new { onclick = "return confirm('Are you sure you want to delete this User?');" }) %> </td> 在Global.asax.cs routes.MapRoute( "DeleteUser","Account.aspx/DeleteUser/{uname}",new { controller = "Account",action = "DeleteUser",uname = "" } ); 在ActionContorller.cs public ActionResult DeleteUser(string uname) { //delete user } 控制器中uname的值正在传递为空字符串(“”). 解决方法尝试这样:<%= Html.ActionLink( "Delete","Account",new { uname = item.UserName },new { onclick = "return confirm('Are you sure you want to delete this User?');" } ) %> 然后确保生成的链接正确: <a href="/Account.aspx/DeleteUser/foo" onclick="return confirm('Are you sure you want to delete this User?');">Delete</a> 另请注意,不推荐使用纯GET动词来修改服务器上的状态. 这是我会推荐你的: [HttpDelete] public ActionResult DeleteUser(string uname) { //delete user } 并认为: <% using (Html.BeginForm( "DeleteUser",new { uname = item.UserName },FormMethod.Post,new { id = "myform" }) ) { %> <%= Html.HttpMethodOverride(HttpVerbs.Delete) %> <input type="submit" value="Delete" /> <% } %> 并在一个单独的javascript文件中: $(function() { $('#myform').submit(function() { return confirm('Are you sure you want to delete this User?'); }); }); 您也可以考虑添加一个anti forgery token来保护此操作免于CSRF attacks. (编辑:4S站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET页面验证
- asp.net – $(“#dialog”).parent().appendTo($(“form:f
- asp.net-mvc-4 – MVC4 RC脚本捆绑很慢
- .net – 可以为空的枚举类型的奇怪行为
- asp.net – 如何MSDeploy构建的网站包到一个处女IIS网站
- 从ASP.NET应用程序使用Active Directory时,DirectoryServic
- asp.net-mvc – MVC DB首先修复显示名称
- asp.net – Request.Url.AbsoluteUri和重写的URL
- 有没有办法加快asp.net中的编辑 – 编译 – 调试周期?
- asp.net后台cs中的JSON格式变量在前台Js中调用方法(前后台示
推荐文章
站长推荐
- asp.net – 网站随时随地突破
- asp.net – IIS 404自定义错误不能按预期工作
- asp.net-mvc – 缩小ASP.NET MVC中的Action Filt
- asp.net-mvc-2 – 使用’class(或其他保留关键字
- asp.net – VB.NET – 如何使用Active Directory
- asp.net-mvc – 使用与本地化更改冲突的自定义数
- 在ASP.NET中,获取基本UR1请求的最快方法是什么?
- asp.net-mvc – 寻找第三方CMS与MVC网站集成
- asp.net – 为什么Global.asax事件在我的ASP.NET
- 在IIS上部署ASP.NET Core项目的图文方法
热点阅读