LiverpoolsNumber9
LiverpoolsNumber9

Reputation: 2394

Kendo UI (MVC) Grid AJAX binding form data not sent

Does anybody know what the "Data" part of the Grid Ajax Read fluent API does.

The reason I ask is because my set up is like this:

// razor setup
.Kendo()
.Grid<MyModel>()
.Name("KENDO_UI_GRID")
.DataSource(d =>
    d.Ajax()
    .Read(r => r
        .Data("k_get_datafromform")
        .Action("ResultsJson", "ControllerName")
    )
    .Events(e => e.RequestEnd("k_grid_requestend"))
    .Events(e => e.Error("k_grid_error"))
    .PageSize(Model.MaxItemsPerPage))
.Columns(// etc etc


// javascript function  
function k_get_datafromform() {
    var theFormFound = jQuery(".search-form:first");
    if (theFormFound) {     
        // custom helper to convert form to object
        return theFormFound.serializeObject();
    };
    return null;

}

But when the grid POSTs to get the results, it doesn't send the data along with it. The form collection contains the usual Kendo stuff (pagesize etc) but nothing else. What am I doing wrong???

Upvotes: 1

Views: 2309

Answers (3)

LiverpoolsNumber9
LiverpoolsNumber9

Reputation: 2394

From Telerik:

"This is a known issue in the first service pack release(2013.3.1316) that is already fixed. The additional data for the read request was not included in the serialized request data and was not sent to the server. Please update the version that you are using to the latest service pack(2013.3.1324) which is available for download from your account. I am sorry for the inconvenience caused."

And that's that.

Upvotes: 2

CSharper
CSharper

Reputation: 5580

For example, here is a DropdownList (left stuff out to be more clear) that requires additionalData, you'll notice the javascript function "OnAdditionalData" in the .data tag

@(Html.Kendo().DropDownListFor(x => x.FromOpportunity)
          .Name("OpportunityDDL")                                                    
          .DataSource(source => {
              source.Read(read =>
               {
                   read.Action("SomeMethod", "SomeController")
                      .Data("OnAdditionalData");
               })                   
   )     

and The JS

 function OnAdditionalData() {
    var Item = 3      
    return {             
        partyItem: Item
    };
}

So when the data is read it says ok, go to SomeMethod in SomeController and read the Data, but says wait! i need data, what am I bringing to the party. It looks at the JS function and says ok I have a partyItem with a value of 3.

public JsonResult SomeMethod(int partyItem)
    {
       // partyItem will == 3
    }     

Notice "partyItem" in the controller is the same name as "partyItem" in the function, they must be the same. Be aware that if you expected a string in the Controller it wouldn't work. if it was var Item = "3" then it would work.

Upvotes: -1

Petur Subev
Petur Subev

Reputation: 20193

You are using the Data function to send addtional parameters to the server, when the dataSource is performing the operation - in your case the Read operation.

So if you return from the function something like {foo :42}. This parameter equal to 42 will be send to the server.

In your case I assume that the result from the serializeObject is not right.

Can you try to see how you object looks like and share it with us?

You can use

alert(kendo.stringify(theFormFound.serializeObject()));

or

console.log(kendo.stringify(theFormFound.serializeObject())

to investigate

Upvotes: 1

Related Questions