Load data from SQL to Kendo UI DropDownList

870 Views Asked by At

I learning how to call server side function when user click Kendo button.

I read from this topic Call a server side MVC action on the click of a Kendo UI button

---- This is original post ----

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 });
}

-----End original post ------------

Can someone explains more about this example or explains more detail example? - I don't understand what is data, do we really need write code in .done and fail?

This is my view:

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

This is my JS function

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

This is my Controller

namespace KendoMVCWrappers.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Kloon test Kendo UI ASP.NET MVC application by Pham Thai Son";

            return View();            
        }

        private JsonResult GetView(DataSourceRequest request)
        {
            return Json(GetData().ToDataSourceResult(request));
        }    
    }
}
1

There are 1 best solutions below

0
On

Kendo allows you to populate their widgets using JS or Razor. I personally use Razor, but have used both. The Kendo examples sometimes just show one or the other. As for calling a function on Kendo button click, you do not have to put anything in the .done and .fail functions, but .done or success is where you could place the function to populate the drop down once the button was clicked. .data holds the returned data from calling the onClick function in the first place, and .done and .fail allows you do things with it based on success or fail.

Do you want to know how to populate a drop down as your title suggests or do you want their example explained?