View Full Version : Ext.Data.JsonStore passing complex objects

13 Aug 2009, 6:06 PM
Hi so I'm using ExtJs and MVC, specifically a Ext.data.JsonStore for a data grid which calls a controller action to return the data for the grid.

So I have the store I set the url to the action's url, this calls the action fine with start and limit set.

The tricky part is I want to pass a complex object to the the action with the query parameters for the search.

The object comes from the view's strongly typed data model, this is not a probelm I use it in the view to construct the baseParams.

The problem is that it arrives at the controller as a String = "[object Object]" instead of an object with all the relevant properties.

My data store looks like this:

Ext.onReady(function() {
var ds = new Ext.data.JsonStore({url: '/crm/Customer/SearchAccounts'
,root: 'Rows'
,totalProperty: 'RowCount'
,idProperty: 'Id'
,fields: [{name: 'Id'
{name: 'AccountNumber'
{name: 'AccountName'
{name: 'Contacts'
,baseParams: {
crit : {
,CustomerId : 'Model.CustomerId'
,UserName : 'Model.UserName'
,Surname : 'Model.Surname'
,PhoneNumber : 'Model.PhoneNumber'
,Firstname : 'Model.Firstname'

ds.load({ params: { start: 0, limit: 15} });

The controller action looks like this:

public JsonResult SearchAccounts(CustomerSearchCriteria crit, int start, int limit)

in this form crit is null.

When I try like this:

public JsonResult SearchAccounts(String crit, int start, int limit)

crit = "[object Object]"

When I try like this

public JsonResult SearchAccounts(Object crit, int start, int limit)

crit = { string[1] = "[object Object]"}

What am I doing wrong?!?! am I just missing the point here or what?

I think I might be building or passing the object wrong.

Any help much appreciated.

16 Aug 2009, 8:11 AM
try :

var baseParams = Ext.encode({
crit : {
,CustomerId : 'Model.CustomerId'
,UserName : 'Model.UserName'
,Surname : 'Model.Surname'
,PhoneNumber : 'Model.PhoneNumber'
,Firstname : 'Model.Firstname'

then baseParams : baseParams

19 Aug 2009, 10:24 PM
After more research something like that may have worked with a custom model binder... instead i used this:
basparams: {
crit.CustomerId : 'Model.CustomerId',
crit.UserName : 'Model.UserName',
crit.Surname : 'Model.Surname',
crit.PhoneNumber : 'Model.PhoneNumber',
crit.Firstname : 'Model.Firstname',