ASP.NET MVC删除操作链接确认
发布时间:2020-12-30 10:37:18 所属栏目: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中使用NVP API时,PayPal SetExpressCheckout存在问
- asp.net-mvc – 未在ELMAH中记录的错误
- asp.net core 实现一个简单的仓储的方法
- asp.net-web-api – Web API / MVC 6中的安全JSON Web令牌
- .net – ReportViewer 2010无法评估表达式
- ASP.NET:隐藏gridview中的列
- .net – 有人有一个例子,说明为什么我会主持一个WCF服务
- asp.net-mvc-3 – 如何在ASP.NET MVC中创建递归结构
- asp.net中js+jquery添加下拉框值和后台获取示例
- ASP.NET 2.0和4.0似乎在Forms身份验证中以不同方式处理根UR
推荐文章
站长推荐
- asp.net-mvc – ASP.NET MVC:Action中的授权 –
- WCF服务与ASP.NET Web Api
- 经典ASP和UTF-8
- asp.net – 如何MSDeploy构建的网站包到一个处女
- asp.net – [DataType(DataType.EmailAddress)]和
- asp.net-mvc – 发现MVC项目中是否使用views / p
- asp.net-mvc – 使用与本地化更改冲突的自定义数
- ASP.NET缓存的方法和最佳实践
- asp.net – 我可以愚弄HttpRequest.Current.Requ
- asp.net-mvc – Visual Studio 2010 Full和ASP.N
热点阅读