ASP.NET MVC删除操作链接确认
发布时间:2020-05-22 22:34:03 所属栏目: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 MVC应用程序的全文搜索的最佳方法是什么?
- asp.net – Nlog不创建相对于网站项目的文件
- asp.net – 如何在runat =“server”表单元素中包含thead?
- asp.net – 使用AJAX进行WCF调用
- asp.net – MVC 4 Web API Action返回:类型vs HttpRespons
- asp.net-mvc-3 – SignalR多个聊天室
- asp.net-mvc – MVC企业领域 – 好还是坏?
- ASP.net MVC Webforms视图引擎的缺点?
- asp.net-mvc-2 – 读取HTTP请求自定义标头
- asp.net – 如何发布站点从命令行与一些发布配置文件?
推荐文章
站长推荐
- asp.net – 在Web.config帮助中定义tagPrefixes
- asp.net-mvc – Server 2008 R2上的MVC – 如何?
- asp.net编程实现删除文件夹及文件夹下文件的方法
- asp.net – Tridion分析和个性化错误:用户不能为
- asp.net-mvc – ASP.Net MVC中的线程安全性
- asp.net-mvc – ASP.NET MVC 5如何在Identity 2.
- ASP.Net:将客户端onClick添加到GridView中的Hyp
- asp.net-mvc – ASP.NET MVC 4邮政编码验证
- asp.net-mvc – 为什么Chrome在ASP.NET MVC中提供
- asp.net – ReportViewer超时,尽管超时设置
热点阅读
