javascript – 在剃刀中确认Url.Action

前端之家收集整理的这篇文章主要介绍了javascript – 在剃刀中确认Url.Action前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨我在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>
@H_301_4@但是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>
@H_301_4@顺便说一句,您应该考虑使用帮助器:

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>
)
原文链接:https://www.f2er.com/js/155595.html

猜你在找的JavaScript相关文章