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

Ajax Select() passing parameters

3 Answers 266 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tim
Top achievements
Rank 1
Tim asked on 12 Jan 2012, 09:48 PM
I am having issues passing values to a controller action with Ajax client binding...

My binding is setup as:
.DataBinding(dataBinding => dataBinding
                            .Ajax()
                                .Select("GetContractLineItems", "Adjustment")
                        )

If I setup a button with a click event to refresh the grid using the following javascript, my 2 action arguments have values...
$("#OrderItems").data("tGrid").rebind({ selectedDocumentOrders: items, tttest: "351331" });

However, because this is a click event, when the grid initially loads and the action parameters are blank.  Therefore I started looking at the OnDataBinding Client Event...
If I remove the arguments from the .rebind above in the click event, wire up the client event, and implement the event as follows:
    ...
    .ClientEvents(events => events.OnDataBinding("onDataBinding"))
    ...
 
function onDataBinding(e) {
    var items = "";
 
    ... set items ...
 
    e.Data = { selectedDocumentOrders: items, tttest: "351331" };
}
 I found that on both the initial load and the click event, that this function is invoked, the e.Data is initially undefined and then set.  However in both situations the controller action arguments are now null.

I even tried changing the e.Data assignment to:
e.Data = { "selectedDocumentOrders": items, "tttest": "351331" };
To no avail...

I am running in a MVC3 web site and Telerik was installed via NuGet and is version 2011.3.1115.  I am using the JQuery and jquery validate that shipped with Telerik along with other jquery libraries...

Any ideas why the onDataBinding is not working for me?

Additionally, when the parameters are sent with the rebind method, if I break in the controller action, I see the HttpContext.Request.Forms collection contains the 2 arguments as indexes 1 & 2  (0 is page).  When set via e.Data, the HttpContext.Requests.Forms collection only contains 1 element (key=page)

3 Answers, 1 is accepted

Sort by
0
Bob
Top achievements
Rank 1
answered on 12 Jan 2012, 10:00 PM
I just do this right in the View:

.Select("AjaxDefaultBudgetVersions", "Company", new { id = Model.EntityKey })

Not sure if that will work for you.

BOb
0
Tim
Top achievements
Rank 1
answered on 12 Jan 2012, 10:06 PM
usually yes, but not in this case...

The items is actually a comma delimited list (workaround) of checkbox values and the rebind trigger is change event of each the checkbox...  Essentially for every parent checkbox, add it's children to the grid...  [Won't even mention that I really wanted the items to be an IEnumerable set of my model, but that is not supported... -- or did I just do that :) ]

0
Bob
Top achievements
Rank 1
answered on 12 Jan 2012, 10:15 PM
Ah gotcha,

Although, I don't see why you couldn't load data with a js array of js objects. The MVC model binder should be able to deal with that. 

BOb
Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Bob
Top achievements
Rank 1
Tim
Top achievements
Rank 1
Share this question
or