我有這個 URL 操作:
<a href="@Url.Action("DeleteCat", "GlobalTagging", new { id = Model.MainNodes[i].Id})">L?schen</a>
這會在我的代碼后面觸發一個函式:
public ActionResult DeleteCat(int? id) { }
問題是我無法在兩者之間插入確認對話(是/否)。我試過用javascript:
function DeleteCat(value) {
*ALERT*
@Url.Action("DeleteCat", "GlobalTagging", new { value})
}
但問題是,我無法將 js 引數傳遞給 c# 函式,因為它們來自不同的運行時。
所以我需要從我猜的代碼中觸發警報,但我還沒有找到任何有效的解決方案。
我確實遇到過這個:
Response.Write("<script>alert('Data inserted successfully')</script>");
但是我無法用是/否選項來填充對話框并做出回應。也許這段代碼可以改變,所以它可以在c#中使用?
歡迎任何想法!
謝謝!
uj5u.com熱心網友回復:
您可以通過錨點的屬性或呼叫來創建click事件onclickyouritem.addEventListener('click', redirect);
function redirect(event) {
if (!confirm("Are you sure")) event.preventDefault();
}
<a href="https://stackoverflow.com" onclick="redirect(event)">Foo</a>
function redirect(event) {
if (!confirm("Are you sure")) event.preventDefault();
}
document.getElementById("foo").addEventListener('click', redirect);
<a id="foo" href="https://stackoverflow.com">Foo</a>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/531715.html
標籤:C#网剃刀
