嗨我在gridview中使用编辑按钮.在打电话给行动之前,我想要一个确认按钮?
grid.Column("","",format:@<text>@if(!item.IsBookPublished) { <text> <a href='@Url.Action("EditBookByID","Books",new {BookID = @item.BookDetailsID,CreatedBy = @item.UserID,onclick = "return confirm('Are you sure you want to Edit?')" })'>Edit</a></text> } </text>
但是onclick属性没有评估,而是作为参数传递.我怎样才能确认?
解决方法
你把它放在了错误的地方.现在你已经将它作为参数传递给Url.Action助手,而它应该是一个单独的属性,就像你定义href属性一样:
<a href="@Url.Action("EditBookByID",new { bookID = item.BookDetailsID,CreatedBy = item.UserID })" onclick="return confirm('Are you sure you want to Edit?')">Edit</a>
顺便说一句,您应该考虑使用帮助器:
grid.Column("",format: @<text> @if(!item.IsBookPublished) { Html.ActionLink( "Edit","EditBookByID",new { bookID = @item.BookDetailsID },new { onclick = "return confirm('Are you sure you want to Edit?')" } ) } </text> )