1

在我的页面中,我有以下脚本:

<script language="javascript">
    var needToConfirm = true;

    window.onbeforeunload = confirmExit;

    function confirmExit() {
        if (needToConfirm) {
            return "You have attempted to leave this page. " +
                "If you have made any changes to the fields without clicking the Save button, your changes will be lost." +
                " Do you wish to proceed?";
        }
    }
</script>

我可以在这样的按钮中设置 needToConfirm 值:

<input type="submit" value="Save" name="_submitButton" onclick="needToConfirm = false"/>

我想知道在这样的 actionLink 中是否有类似的方法:

@Html.ActionLink("Remove this item", "RemoveItemEdit", new
                            {
                                @_cardID = Model.mPackToEdit.mListCardPack[i].mCard.mMasterCard.mCardID,
                                needToConfirm = false
                            })

我已经尝试过了,但它不起作用。

4

2 回答 2

2

第三个参数ActionLink是路由值。您需要将 放入needtoconfirm第四个参数 - htmlAttributes。试试这个:

@Html.ActionLink(
    "Remove this item", 
    "RemoveItemEdit", 
    new { @_cardID = Model.mPackToEdit.mListCardPack[i].mCard.mMasterCard.mCardID },
    new { "onclick" = "needToConfirm = false" })
于 2013-09-04T14:27:17.890 回答
1

您当前使用的版本Html.ActionLink 是设置路由值。您要设置html 值

试试这个:

@Html.ActionLink("Remove this item", "RemoveItemEdit", 
    new { 
        _cardID = Model.mPackToEdit.mListCardPack[i].mCard.mMasterCard.mCardID
    },
    new { 
        needToConfirm = false
    });
于 2013-09-04T14:26:51.873 回答