Answers:
不要routeValues
与混淆htmlAttributes
。您可能想要此重载:
<%= Html.ActionLink(
"Delete",
"Delete",
new { id = item.storyId },
new { onclick = "return confirm('Are you sure you wish to delete this article?');" })
%>
这些是您传递的路线
<%= Html.ActionLink("Delete", "Delete",
new { id = item.storyId },
new { onclick = "return confirm('Are you sure you wish to delete this article?');" }) %>
您要查找的重载方法是以下一种:
public static MvcHtmlString ActionLink(
this HtmlHelper htmlHelper,
string linkText,
string actionName,
Object routeValues,
Object htmlAttributes
)
<%= Html.ActionLink("Delete", "Delete",
new { id = item.storyId },
new { onclick = "return confirm('Are you sure you wish to delete this article?');" }) %>
上面的代码仅适用于Html.ActionLink。
对于
Ajax.ActionLink
使用以下代码:
<%= Ajax.ActionLink(" ", "deleteMeeting", new { id = Model.eventID, subid = subItem.ID, fordate = forDate, forslot = forslot }, new AjaxOptions
{
Confirm = "Are you sure you wish to delete?",
UpdateTargetId = "Appointments",
HttpMethod = "Get",
InsertionMode = InsertionMode.Replace,
LoadingElementId = "div_loading"
}, new { @class = "DeleteApointmentsforevent" })%>
“确认”选项指定javascript确认框。
使用webgrid,您可以在这里找到它,操作链接如下所示。
grid.Column(header: "Action", format: (item) => new HtmlString(
Html.ActionLink(" ", "Details", new { Id = item.Id }, new { @class = "glyphicon glyphicon-info-sign" }).ToString() + " | " +
Html.ActionLink(" ", "Edit", new { Id = item.Id }, new { @class = "glyphicon glyphicon-edit" }).ToString() + " | " +
Html.ActionLink(" ", "Delete", new { Id = item.Id }, new { onclick = "return confirm('Are you sure you wish to delete this property?');", @class = "glyphicon glyphicon-trash" }).ToString()
)
带有图片和删除确认信息,适用于mozilla firefox
<button> @Html.ActionLink(" ", "action", "controller", new { id = item.Id }, new { @class = "modal-link1", @OnClick = "return confirm('Are you sure you to delete this Record?');" })</button>
<style>
a.modal-link{ background: URL(../../../../Content/Images/Delete.png) no-repeat center;
display: block;
height: 15px;
width: 15px;
}
</style>
我想要同样的东西;我的详细信息视图上的删除按钮。我最终意识到我需要从这种观点发布:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.Id)
@Html.ActionLink("Edit", "Edit", new { id = Model.Id }, new { @class = "btn btn-primary", @style="margin-right:30px" })
<input type="submit" value="Delete" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this record?');" />
}
并且,在控制器中:
// this action deletes record - called from the Delete button on Details view
[HttpPost]
public ActionResult Details(MainPlus mainPlus)
{
if (mainPlus != null)
{
try
{
using (IDbConnection db = new SqlConnection(PCALConn))
{
var result = db.Execute("DELETE PCAL.Main WHERE Id = @Id", new { Id = mainPlus.Id });
}
return RedirectToAction("Calls");
} etc
更新/编辑/删除记录之前的任何单击事件消息框都会警告用户,如果继续执行操作“确定”,否则“取消”保持不变。对于此代码,无需对单独的Java脚本代码进行修改。这个对我有用
<a asp-action="Delete" asp-route-ID="@Item.ArtistID" onclick = "return confirm('Are you sure you wish to remove this Artist?');">Delete</a>
您也可以为Html.ActionLink DeleteId尝试此操作