2012-02-04 51 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