Call controller method on button click

2 posts, 0 answers
  1. marbleblue
    marbleblue avatar
    12 posts
    Member since:
    Apr 2008

    Posted 10 Dec 2012 Link to this post


    I'm currently playing with aspnet webforms with jquery (via kendo mobile). I have the following setup below. In the aspx page,
    I need to call the 'Book' method in a 'controller' on a button click. I'm guessing I will need to use $.ajax? or is there another way via kendo dataSource? any sample code of the 'ajax' call would really help as i'm at the earliest stages of learning this stuff,

    Kind regards.

    function showShiftDetailView(e) {
            var view = e.view;

            sds.fetch(function () {
                item = sds.get(;
           $('<a data-role="button" id="bookbutton">Book</a>').insertBefore('#shiftdetaillistview');
           $('#bookbutton').click(function () {
                    // **** 1. call book function

    function BookShift(id) {
       *** 2. call 'Book' method with parameter here and get response**
      $.ajax ?

     public class ShiftController : ApiController
            private Data.Shift _context = new Data.Shift();
            HttpRequest _request = HttpContext.Current.Request;

            // WebAPI will respond to an HTTP GET with this method
            public Model.Response Get()
                // the the take and skip parameters off of the incoming request
                int take = _request["take"] == null ? 10 : int.Parse(_request["take"]);
                int skip = _request["skip"] == null ? 0 : int.Parse(_request["skip"]);

                var entries = (from System.Data.DataRow r in _context.GetData().Rows
                               select new Model.Shift(r)).Skip(skip).Take(take).ToArray();

                return new Model.Response(entries, _context.GetData().Rows.Count);

    // **** 3.  I want to call this from a button click *** //
            public Model.Response Book(string tempShiftPlanid)
                IPoint.Shifts.Shift shift = new IPoint.Shifts.Shift();
       =  id;
                return new Model.Response(shift.BookShift());

    // Response.cs
    public class Response
            public string DBData { get; set; }

            public Response(string dbdata)
                this.DBData =dbdata;
  2. Petyo
    Petyo avatar
    2444 posts

    Posted 11 Dec 2012 Link to this post


    Your question is not directly related to Kendo UI Mobile. I would like to suggest that you check these stack overflow discussions:

    Or any of the google results of this search query.

    As a side note, I would like to direct you to this demo for the correct way to handle button widget click events

    Kind regards,
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top