0
- 我有一些數據通過Ajax綁定加載到Kendo網格中。
- 在其中一列中有一個ClientTemplate,它調用一個javascript方法(showAll)。
- 此方法將調用一個操作並獲取數據的詳細信息,將其放入一個json響應中,然後打開一個jquery-ui對話框以顯示詳細信息。
- 當用戶點擊網格中的鏈接時,HttpGet被觸發以執行GetDetails動作,但問題是,它也觸發了整個頁面的動作(Index)。
問題,我想是什麼導致索引動作被觸發?因爲對話框會顯示詳細的數據,但是一旦關閉對話框,所有的過濾器文本框就會被重置,並且網格將重新加載並且數據將被重新加載。Kendo UI Grid - ClientTemplate調用MVC Url.Action調用(錯誤地)兩個不同的動作
不應該是唯一被稱爲GetDetails的操作嗎?
任何提示將不勝感激!
代碼:
@(Html.Kendo().Grid<LogViewModel>()
.Name("LogGrid")
.Columns(column =>
{
column.Bound(x => x.StuffCount).Title("Stuff").Width(70)
.ClientTemplate("<a onclick=\"showAll('" + "#= Id #')\"" + " href=''>#= StuffCount #</a>");
})
.DataSource(dataBinding => dataBinding
.Ajax()
.PageSize(50)
.Read(read => read.Action("GetData", "Summary")
.Data("getSearchFilters"))
.Model(model => model.Id(o => o.Id)))
.Events(e => e
.DataBound("onGridItemsDatabound"))
.Pageable(paging => paging.Refresh(true))
)}
<div id="dialog-message" title="" style="display: none">
<p id="msg"></p>
</div>
<script type="text/javascript">
var showAll= function (id) {
var url = '@Url.Action("GetDetails", "Summary")' + "/" + id;
var sTitle = 'title text';
$.getJSON(url, null,
function (data) {
$("#dialog-message").dialog({ title: sTitle });
$("#msg").text(data.details);
showMessage();
});
};
var showMessage = function() {
$("#dialog-message").dialog({
modal: true,
draggable: false,
resizable: false,
buttons: {
Ok: function() {
$(this).dialog("close");
}
}
});
};
</script>
控制器方法(爲簡便起見
public ActionResult Index(...)
{
...
}
public ActionResult GetDetails(Guid id)
{
... (get data from repository)
return Json(data, JsonRequestBehavior.AllowGet);
}