Call a server side MVC action on the click of a Kendo UI button

五迷三道 提交于 2019-12-09 12:14:32

问题


I just download a trial version of v2013.3.1119.440 of the Kendo UI wrappers for ASP.NET MVC. I see a new Kendo.Mvc.UI.Fluent.ButtonBuilder wrapper in this version that wasn't in the version I had downloaded just 20 days ago on another PC.

The said wrapper represents a button.

I can't see a way to directly wire this Kendo.Mvc.UI.Fluent.ButtonBuilder wrapper with a server side MVC action. How do I do that?

I do see the Events method on the ButtonBuilder class, which accepts a Action<ButtonEventBuilder> events. In the ButtonEventBuilder, I see another method called Click, which has two overloads, but both are for wiring client side event handlers of the button.

I don't see a way to directly wire up a server side call-back/post-back with the button click.

Am I missing something? Is the only way to do it the manual way of firing the server side post back or call back from a JavaScript function?


回答1:


The Button is new in the latest release of Kendo UI (last week). It doesn't directly support what you're looking for, but something similar could be accomplished like this:

@(Html.Kendo().Button()
    .Name("textButton")
    .Content("Text button")
    .HtmlAttributes( new {type = "button"} )
    .Events(ev => ev.Click("onClick")))

Then a JS function similar to this:

function onClick(){
    $.ajax({
        url: '/controller/action'
        data: { // data here }
    }).done(function(result){
        // do something with the result
    }).fail(function() { // handle failure });
}

More info can be found in their demo site: http://demos.kendoui.com/web/button/events.html



来源:https://stackoverflow.com/questions/20219730/call-a-server-side-mvc-action-on-the-click-of-a-kendo-ui-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!