PDA

View Full Version : Values not Populating in COMBOBOX even though it is fired the values from MVC



samsi
29 Sep 2013, 6:16 PM
Hi all,

I am Very new to EXTJS.

i am adding a new combo to my html page using EXTJS in xxx.js file and fetching the values from MVC controller with sample information.

while debugging the MVC application it is sending the sample information when i send URL: xxxx/getSite from EXTJS.

but it is not showing the values which are fetching from Controller. i am adding the below code which i am using.

Please let me know my mistake.

My Ext JS Code:


var siteidStore = new Ext.data.JsonStore({
reader: new Ext.data.JsonReader({
fields: ['SiteName','SiteId']
}),
root: 'Site',
proxy: new Ext.data.HttpProxy({
url: 'Templates/getSite',
method: "POST",
type: 'ajax',
reader: 'json'
}),
autoLoad: true
});
var combo = Ext.create('Ext.form.field.ComboBox', {
queryMode: 'local',
store: siteidStore,
fieldLabel: 'Site ID',
name: 'siteid',
displayField: 'SiteName',
valueField: 'SiteId',
triggerAction: 'all',
typeAhead: false,
forceSelection: true,
emptyText: 'Select Site',
hiddenName: 'SiteId',
selectOnFocus: true
});



MY MVC Appln Code from Controller.

publicActionResult getSite()
{
List<Combo> siteid = newList<Combo>();
siteid.Add(newCombo(1, "IND"));
siteid.Add(newCombo(2, "USA"));
siteid.Add(newCombo(3, "UK"));
return Json(new
{
Site = siteid,
}, JsonRequestBehavior.AllowGet);
}


Thanks

evant
29 Sep 2013, 6:21 PM
There's not a lot of value in posting your server code, we only really need to know what the output is.

samsi
29 Sep 2013, 6:34 PM
Need to fill the Values in COMBOBOX with SITENAME as IND,USA,UK
using MVC application,

For Example:
46060

evant
29 Sep 2013, 6:47 PM
Yes, I understand, but what is the output of your C# code? What JSON does it produce?

samsi
29 Sep 2013, 7:08 PM
{"Site":[{"SiteName":"IND","SiteId":1},{"SiteName":"USA","SiteId":2},{"SiteName":"UK","SiteId":3}]}

samsi
30 Sep 2013, 5:39 PM
can anyone Reply please?

Ilay
30 Sep 2013, 10:08 PM
I think, you use root: 'Site' incorrect, in wrong place. It's a "reader" property

samsi
1 Oct 2013, 12:48 AM
I got the partial solution:


var StrSiteID = new Ext.data.JsonStore({
storeId: 'SiteIDStore',
proxy: {
type: 'ajax',
url: 'Templates/getSite',
reader: {
type: 'json',
root: 'Site'
}
},
fields: ['SiteName', { name: 'SiteId', type: 'number' }],
autoLoad: true
});
by using the above Store. But only problem i am facing now,not able to bind the values for combobox if it is placed inside the "XTYPE: CONTAINER"