ASP.NET MVC删除操作链接确认
发布时间:2020-12-30 11:47:25 所属栏目: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 Excel导出编码问题
- asp.net-mvc – 使用jQuery.post将多个参数发布到MVC Contr
- ASP.NET中的应用程序生存期
- 强烈推荐的一个工具ReSharper
- 增加ASP.NET站点的executionTimeout和maxRequestLength是否
- asp.net-mvc – ASP.NET MVC路由和静态数据(即图像,脚本等)
- ASP.NET 清除模式窗口数据缓存的操作方式
- asp.net – Azure可以运行WPF吗?
- asp.net-mvc-3 – ASP.Net MVC 3:在哪里处理会话丢失?
- asp.net-mvc – 有条件地在webgrid中显示图像 – mvc 3
推荐文章
站长推荐
- 密码由6-12位数字或字母组成,密码哈希加密
- 十七点学完安全知识超级详细了解进程和病毒知识
- asp.net实现生成缩略图及给原始图加水印的方法示
- asp.net – 注册.NET 4.5 IIS 10 Windows 10
- 从app_data中删除文件夹时如何防止asp.net重新编
- asp.net – 使用FormsAuthentication持久的cooki
- asp.net – ASP MVC – 默认的HTTP标头有任何常量
- 为什么asp.net将页面包装在一个表单中?
- asp.net-mvc – 使用NLog记录未处理的异常? ELM
- asp.net-mvc-4 – ASP.NET MVC 4通过ActionLink传
热点阅读
