[英]How to get confirm message on Url.Action?
在这里,我想在单击删除按钮时使用我在Html.Action
上使用 onclick 的任何 jquery 获得确认消息,如下所示
<button type="button" class="btn btn-danger" onclick="location.href='@Url.Action("Delete","StudentDetails", new { id=item.StudentId}, new { onclick = "return confirm('Are sure wants to delete?');" } )'"><i class="fa fa-trash" aria-hidden="true"></i></button><br>
但它在new { id=item.StudentId}
上显示了一个错误,指出"cannot convert from '<anonymous type: int id>'to 'System.Web.Routing.RouteValueDictionary'>"
并且Cannot convert from '<anonymous type:string onclick>'to 'string'
任何帮助都会很棒
把它分开可能更容易。
将 URL 添加到数据属性,例如
<button data-url="@Url.Action("Delete","StudentDetails", new { id=item.StudentId})" onclick="ConfirmDeletion()"></button>
然后onclick可以调用一个javascript函数
function ConfirmDeletion()
{
var x = confirm("Are you sure you want to delete?");
if (x) {
var url = this.getAttribute('data-url')
location.href= = url;
}
}
我没有测试过这个,但我认为它更简单更清晰
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.