簡體   English   中英

Kendo UI Grid-調用MVC Url.Action的ClientTemplate調用(錯誤地)兩個不同的操作

[英]Kendo UI Grid - ClientTemplate calling MVC Url.Action calls (incorrectly) two different actions

  1. 我有一些數據通過Ajax綁定加載到Kendo網格中。
  2. 在其中一列中,有一個ClientTemplate調用javascript方法(showAll)。
  3. 此方法將調用操作並獲取數據的詳細信息,將其放入json響應中,然后打開jquery-ui對話框以顯示詳細信息。
  4. 當用戶單擊網格中的鏈接時,將為GetDetails操作BUT觸發HttpGet,問題是,它也為整個頁面的操作(索引)觸發。

我猜,問題是什么導致“索引”操作被觸發? 因為將顯示該對話框,所以將填充詳細數據,但是一旦關閉該對話框,所有過濾器文本框將被重置,網格將重新加載,其中的數據將被重新加載。

唯一的動作不應該是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);
}

我在Telerik論壇上發布了相同的問題。 他們的管理員為我指明了正確的方向:

原來,我不得不在href中添加空格以調用javascript並停留在頁面上。 href =“ javascript:void(0)”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM