Cam*_*ron 97 asp.net-mvc actionlink
我正在尝试实现一个ActionLink使用ASP.NET MVC删除记录的简单方法.这是我到目前为止:
<%= Html.ActionLink("Delete",
"Delete",
new { id = item.storyId,
onclick = "return confirm('Are you sure?');"
})%>
Run Code Online (Sandbox Code Playgroud)
但是,它不会显示确认框.很明显我错过了一些东西,或者我错误地构建了链接.有人可以帮忙吗?
Dar*_*rov 207
不要混淆routeValues与htmlAttributes.你可能想要这个重载:
<%= Html.ActionLink(
"Delete",
"Delete",
new { id = item.storyId },
new { onclick = "return confirm('Are you sure you wish to delete this article?');" })
%>
Run Code Online (Sandbox Code Playgroud)
hun*_*ter 15
那些是你传递的路线
<%= Html.ActionLink("Delete", "Delete",
new { id = item.storyId },
new { onclick = "return confirm('Are you sure you wish to delete this article?');" }) %>
Run Code Online (Sandbox Code Playgroud)
您正在寻找的重载方法是这样的:
public static MvcHtmlString ActionLink(
this HtmlHelper htmlHelper,
string linkText,
string actionName,
Object routeValues,
Object htmlAttributes
)
Run Code Online (Sandbox Code Playgroud)
http://msdn.microsoft.com/en-us/library/dd492124.aspx
T G*_*pta 14
<%= Html.ActionLink("Delete", "Delete",
new { id = item.storyId },
new { onclick = "return confirm('Are you sure you wish to delete this article?');" }) %>
Run Code Online (Sandbox Code Playgroud)
以上代码仅适用于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" })%>
Run Code Online (Sandbox Code Playgroud)
"确认"选项指定javascript确认框.
您还可以通过将删除项与消息一起传递来自定义 。在我使用 MVC 和 Razor 的情况下,我可以这样做:
@Html.ActionLink("Delete",
"DeleteTag", new { id = t.IDTag },
new { onclick = "return confirm('Do you really want to delete the tag " + @t.Tag + "?')" })
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
129533 次 |
| 最近记录: |