ASP.NET MVC删除操作链接确认
发布时间:2020-12-15 20:18:50 所属栏目: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 在Global.asax.cs routes.MapRoute( "DeleteUser","Accoun
<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 MVC的Telerik控件:这是否违反
- .net – WebApi传输字节数组为空
- asp.net-mvc – 为什么自动忽略ApplicationInsights.config
- asp.net文件下载 – 跟踪下载的大小
- asp.net-mvc – asp.net MVC:禁用一个TextBox
- asp.net-mvc – MVC3:使用ActionMethodSelectorAttribute会
- asp.net – MVC ViewModel错误 – 没有为此对象定义的无参数
- 构建高性能ASP.NET应用的几点建议
- asp.net-mvc – 用于MVC 3的Castle Windsor依赖关系解析器
- asp.net – 在C#中解码Base64字节数组到图像
推荐文章
站长推荐
- asp.net-mvc – 菜单上没有添加控制器,无法在MVC
- asp.net-mvc – 从Scripts.Render中排除的Asp.Ne
- asp.net – 如何修改aspx页面的超时?
- asp.net-web-api2 – 如何在ActionFilter之后,在
- ASP.NET MVC验证属性和Jquery
- asp.net – 如何在代码后面访问span id
- asp.net – Windows Azure启动任务未触发
- 如何在ASP.NET自定义控件中持久保存List属性?
- asp.net-web-api – Web Api gzip压缩
- asp.net – VS2008中的许多ascx-to-one ascx.cs错
热点阅读