This is a migrated thread and some comments may be shown as answers.

Ajax Read

4 Answers 94 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Software
Top achievements
Rank 1
Software asked on 23 Jul 2014, 09:58 PM
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?





4 Answers, 1 is accepted

Sort by
0
Software
Top achievements
Rank 1
answered on 23 Jul 2014, 10:21 PM
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
0
Accepted
Kiril Nikolov
Telerik team
answered on 25 Jul 2014, 02:38 PM
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.

 
0
Software
Top achievements
Rank 1
answered on 25 Jul 2014, 08:22 PM
Thanks we were able to get it working with a basic dropdown and ajax call from javascript instead of using the read method
0
Kiril Nikolov
Telerik team
answered on 28 Jul 2014, 10:14 AM
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.

 
Tags
DropDownList
Asked by
Software
Top achievements
Rank 1
Answers by
Software
Top achievements
Rank 1
Kiril Nikolov
Telerik team
Share this question
or