简体   繁体   English

Kendo UI Grid-调用MVC Url.Action的ClientTemplate调用(错误地)两个不同的操作

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

  1. I have some data that loads into a Kendo grid via the Ajax binding. 我有一些数据通过Ajax绑定加载到Kendo网格中。
  2. Within one of the columns there's a ClientTemplate that calls a javascript method (showAll). 在其中一列中,有一个ClientTemplate调用javascript方法(showAll)。
  3. This method will call an action and get the details of the data, putting it into a json response, and then open a jquery-ui dialog to show the details. 此方法将调用操作并获取数据的详细信息,将其放入json响应中,然后打开jquery-ui对话框以显示详细信息。
  4. When the user clicks on the link in the grid the HttpGet is triggered for the GetDetails action BUT, the problem is, it is also triggered for the entire page's action (Index). 当用户单击网格中的链接时,将为GetDetails操作BUT触发HttpGet,问题是,它也为整个页面的操作(索引)触发。

The question, I guess, is what is causing the Index action to be triggered? 我猜,问题是什么导致“索引”操作被触发? Because, the dialog will show, the detailed data will populate, but once I close the dialog all the filter textboxes will be reset and the grid will reload and the data within it. 因为将显示该对话框,所以将填充详细数据,但是一旦关闭该对话框,所有过滤器文本框将被重置,网格将重新加载,其中的数据将被重新加载。

Shouldn't the only action called be the GetDetails? 唯一的动作不应该是GetDetails吗?

Any hints will be greatly appreciated! 任何提示将不胜感激!

Code: 码:

@(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>

The controller methods (content removed for brevity 控制器方法(为简洁起见,删除了内容

public ActionResult Index(...)
{
    ...
}

public ActionResult GetDetails(Guid id)
{
    ... (get data from repository)

    return Json(data, JsonRequestBehavior.AllowGet);
}

I posted the same question on the Telerik forum. 我在Telerik论坛上发布了相同的问题。 Their admin pointed me in the right direction: 他们的管理员为我指明了正确的方向:

Turns out I had to add the void to the href to call the javascript and stay on the page. 原来,我不得不在href中添加空格以调用javascript并停留在页面上。 href="javascript:void(0)" href =“ javascript:void(0)”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM