Ajax Read

5 posts, 1 answers
  1. Software
    Software avatar
    4 posts
    Member since:
    Feb 2014

    Posted 23 Jul 2014 Link to this post

    I have the following drop-down

    @(
                            Html.Kendo().ComboBox()
                            .Name("products")
                            .HtmlAttributes(new { style = "width:250px" })
                            .DataTextField("ProductName")
                            .DataValueField("ProductID")
                            .AutoBind(false)
                            .DataSource(source => {
                            source.Read(read =>
                            {
                                read.Action("GetList", "Submission", new { elementId = Model.Elements[i].FieldId });
                            })
                            .ServerFiltering(false);
                            })
                        )
    The action is hit and the elementId is pass as expected. Now i need to be able to pass the current form and the data. I try as:
    @(
                            Html.Kendo().ComboBox()
                            .Name("products")
                            .HtmlAttributes(new { style = "width:250px" })
                            .DataTextField("ProductName")
                            .DataValueField("ProductID")
                            .AutoBind(false)
                            .DataSource(source => {
                            source.Read(read =>
                            {
                                read.Action("GetList", "Submission", new { elementId = Model.Elements[i].FieldId }).Data("GetForm");
                            })
                            .ServerFiltering(false);
                            })
                        )
    where the GetForm is a javascript function:
    function GetForm() {
        return $('#subform').serializeArray();
    }
    But using this i cant get to the action: JsonResult GetList(int? elementId,SubmissionElement model)

    Any ideas how can i achieve the passing of the current data in the form to my controller?





  2. Software
    Software avatar
    4 posts
    Member since:
    Feb 2014

    Posted 23 Jul 2014 Link to this post

    I updated the javascript as:

    return { model: $('#subform').serializeArray() };

    Not sure why the url for the ajax shows as: elementId=14&model%5B0%5D%5Bname%5D=......value

    This only happens with serialize array
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Answer
    Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2565 posts

    Posted 25 Jul 2014 Link to this post

    Hi,

    The problem comes from the serializeArray() function. As explained it its API reference it returns an array of name-value pairs which will not work.

    http://api.jquery.com/serializearray/

    What you can do is to get the form data and construct and object that you can send to the controller. It should be something like this:

    function GetForm() {
       return {
          FirstName : $('#firstName').val(),
          LastName : $('#lastName').val(),
       }
    }

    Regards,
    Kiril Nikolov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Software
    Software avatar
    4 posts
    Member since:
    Feb 2014

    Posted 25 Jul 2014 Link to this post

    Thanks we were able to get it working with a basic dropdown and ajax call from javascript instead of using the read method
  6. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2565 posts

    Posted 28 Jul 2014 Link to this post

    Hello,

    I am glad to hear that your project is up and running.

    In case you need any further assistance, please do not hesitate to contact us.

    Regards,
    Kiril Nikolov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET MVC is VS 2017 Ready