2012-02-04 63 views
4

我有如何在MVC3網格中注入JavaScript?

@grid.GetHtml(
    tableStyle: "grid", 
    headerStyle: "head", 
    alternatingRowStyle: "alt", 
    rowStyle: "row", 
    selectedRowStyle: "selected-row", 
    columns: grid.Columns(
    grid.Column("StartDate", "Start Date", style: "column"), 
    grid.Column("EndDate", "Endt Date", style: "column"), 
    grid.Column("Title", "Title", style: "column"), 
    grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.ID }), style: "column-action"), 
    grid.Column(format: (item) => Html.ActionLink("Delete", "Delete", new { id = item.ID }), style: "column-action")) 

我想要做的就是更換grid.Column(format: (item) => Html.ActionLink("Delete", "Delete", new { id = item.ID }), style: "column-action")

<button onclick="$.prompt('Delete',{ buttons: { Ok: true, Cancel: false } })" title="Delete">Delete</button> 

我該怎麼辦呢?

P.S.最後的目標是當我們點擊DELETE按鈕時顯示彈出窗口YES/NO。

回答

2

如果你添加一個類的按鈕,你可以將事件附加到它,就像這樣:

C#

grid.Column(format: (item) => Html.ActionLink("Delete", "Delete", new { id = item.ID }, new { @class = "delete-button" }), style: "column-action")) 

jQuery的1.7+

$(".delete-button").on('click', function() { 
    $.prompt('Delete',{ buttons: { Ok: true, Cancel: false } }) 
}); 

<的jQuery 1.7

$(".delete-button").click(function() { 
    $.prompt('Delete',{ buttons: { Ok: true, Cancel: false } }) 
}); 
+0

您的a pproach看起來不錯...但我得到了以下的東西:Delete你能說一下關於@class嗎? – Terminador 2012-02-04 14:34:42

+0

對不起,我的錯誤,我把風格屬性放在路線值params。我編輯了答案。 – 2012-02-04 14:36:54

+0

嗯,你知道事件$(「。delete-button」)。不開火...你知道我必須執行它嗎? – Terminador 2012-02-04 14:56:31