是否可以在 Html.ActionLink 上同时添加 css class 和 return 确认?

Is it possible to add both a css class AND a return confirm on an Html.ActionLink?

我刚刚接触 MVC,所以我不确定这是否可以使用 ActionLink 来完成。但是我想做的是有一个 Html.ActionLink ,你可以分配一个 CSS class AND 和 return确认。

我已经开始工作了:

@Html.ActionLink("Delete", "Delete", "NWS", new { recordId = Model.Id }, new { @class = "btn btn-danger configDelete" })

我已经开始工作了:

@Html.ActionLink("Delete", "Delete", "NWS", new { recordId = Model.Id }, new { onclick = "return confirm('Are you sure you want to delete this config?')" })

但是当我尝试像这样添加两者时,

@Html.ActionLink("Delete", "Delete", "NWS", new { recordId = Model.Id }, new { @class = "btn btn-danger configDelete" }, new { onclick = "return confirm('Are you sure you want to delete this config?')" })

我收到一个语法错误,内容为“没有给定的参数对应于'IHtmlHelper.ActionLink(string, string, string, string, string, string , 对象, 对象)"

我也试过将 return 确认放在 CSS class 之前,但没关系。这可能与 ActionLink 相关吗?如果没有,有什么地方可以让我做到这一点吗?

与其将它们分成各自的对象,不如将它们合并为一个对象:

new { @class = "btn btn-danger configDelete", onclick = "return confirm('Are you sure you want to delete this config?')" }

请注意,它们都只是生成的 HTML 元素的属性。您可以添加任意多个。它们都需要成为传递给 HTML 辅助方法的同一对象的一部分。