我正在使用Kendo MVC listview。我可以在将值传递给控制器之前捕获视图上的remove()事件但是我找不到如何中断或允许它传递给controller的方法。这是我的观点:
编辑:经过一些搜索后,我发现我需要获取“e”包含的jquery数据。但我仍然无法弄清楚如何去做。
@(Html.Kendo().ListView<AIS.UI.WebService.Proxy.DSrvAllService.NewsItem>()
.Name("listView")
.Events(e=>e.Remove("deleteAnnouncement"))
.TagName("div")
.ClientTemplateId("template")
.AutoBind(true)
.DataSource(dataSource => dataSource
.Model(model => model.Id("ID"))
.PageSize(5)
.Read(read => read.Action("AnnouncementsRead", "Administrator"))
.Destroy(delete=>delete.Action("AnnouncementDelete","Administrator")) )
.Editable()
.Pageable()
)
JS:
function deleteAnnouncement() {
$("#dialog-confirm").css("visibility", "visible");
$("#dialog-confirm").dialog({
resizable: false,
draggable: false,
height: 180,
width: 400,
modal: true,
buttons: {
"Yes": function () {
....
$(this).dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
}
});
}
答案 0 :(得分:1)
在函数开头停止事件然后如果按“是”,您可以用ajax手动发送Id删除功能,然后刷新页面或数据源。
1)'data:{ID:id},'您必须找到所选项目的ID以使用ajax发送参数
2)您必须在控制器功能中添加参数。
3)刷新页面或数据源
function deleteAnnouncement(event) {
event.preventDefault ? event.preventDefault() : event.returnValue = false;
$("#dialog-confirm").css("visibility", "visible");
$("#dialog-confirm").dialog({
resizable: false,
draggable: false,
height: 180,
width: 400,
modal: true,
buttons: {
"Yes": function () {
$.ajax({
url: '@Url.Action("AnnouncementDelete","Administrator")',
type: 'POST',
dataType: "json",
data: { ID: id}, // send Id of selected item
success: function (result) {
if (result.Success) {
alert("basarili") // you don't have to return something
}
else {
alert("Fail");
}
},
async: false
})
$(this).dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
}
});
}
答案 1 :(得分:0)
这是从Listview检索所选数据的工作代码,如果按下“是”按钮,在删除事件完成后将值传递给控制器,它会手动刷新Listview的数据源:
<强>的js 强>:
function refreshdataSource() {
$("#listView").data("kendoListView").dataSource.read();
}
function deleteAnnouncement(e) {
e.preventDefault ? e.preventDefault() : e.returnValue = false;
$("#dialog-confirm").css("visibility", "visible");
var data = e.model["ID"];
$("#dialog-confirm").dialog({
resizable: false,
draggable: false,
height: 180,
width: 400,
modal: true,
buttons: {
Okay: function () {
$.ajax({
type: "POST",
url: '@Url.Action("AnnouncementDelete", "Administrator")',
data: {
ID: data
},
dataType: "text",
success: function () { refreshdataSource(); },
error: function () { alert("Error occured!!!") }
});
$(this).dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}}});
};
查看:强>
@(Html.Kendo().ListView<AIS.UI.WebService.Proxy.DSrvAllService.NewsItem>()
.Name("listView")
.Events(e=>e.Remove("deleteAnnouncement"))
.TagName("div")
.ClientTemplateId("template")
.AutoBind(true)
.DataSource(dataSource => dataSource
.Model(model => model.Id("ID"))
.PageSize(5)
.Read(read => read.Action("AnnouncementsRead", "Administrator"))
.Destroy(delete=>delete.Action("AnnouncementDelete","Administrator")) )
.Editable()
.Pageable()
)