如何获取有关Url.Action的确认消息?

问题描述

在这里,我想在单击删除按钮时不使用任何我曾经在 SELECT * FROM `Users` where Meta_value like "%blonde%" and not exists ( SELECT 1 from `Banned_hair_colors` where `Users`.Meta_value like concat('%',`Banned_hair_colors`.color,'%') ) 上单击过的jquery时获得确认消息,如下所示

Html.Action

显示<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> "cannot convert from '<anonymous type: int id>'to 'System.Web.Routing.RouteValueDictionary'>"上的new { id=item.StudentId}错误
任何帮助都会很棒

解决方法

将其拆分可能更容易。

将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;
}

}

我还没有测试过,但是我认为它更简单明了