ASP.NET MVC删除操作链接确认
发布时间:2020-12-30 11:17:00 所属栏目: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. (编辑:百色站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-core – 使用IdentityServer4生成访问令牌,无需密码
- asp.net-mvc-3 – 在ASP.NET MVC 3中覆盖/禁用授权
- Asp.NEt邮箱验证修改密码通过邮箱找回密码功能
- 防止双击asp.net按钮
- asp.net简单生成XML文件的方法
- asp.net-mvc – ASP.NET MVC:处理取消按钮的正确方法
- ASP.NET Core 1.0 ConfigurationBuilder().AddJsonFile(“a
- asp.net-mvc – ASP.NET MVC WebSite中的ERR_EMPTY_RESPONS
- asp.net中使用repeater和PageDataSource搭配实现分页代码
- asp.net-mvc – MVC4部分视图没有将值加载到“容器”模型中
推荐文章
站长推荐
- 在ASP.Net MVC应用程序中放置初始化代码的位置?
- asp.net-mvc – 不应加载引用程序集以执行
- asp.net-mvc – 防止在ASP.NET MVC中缓存属性,每
- ASP.NET Core中实现用户登录验证的最低配置示例代
- asp.net-mvc-3 – 用于ASP的Telerik扩展. NET MV
- asp.net – 请求URL在IIS 7中无效
- asp.net-mvc-2 – 在名称中使用连字符处理MVC2变
- asp.net-mvc – 尝试创建类型为’TypeNewsContro
- asp.net-mvc-3 – 在MVC Razor View中使用If语句
- asp.net – 何时覆盖OnError?
热点阅读