PDA

View Full Version : ASP.NET MVC and EXT JS Combo Box



ewomack
10 Feb 2011, 2:09 PM
Hello, I'm trying to do something relatively simple and I think I'm missing something. All I'm trying to do is call a LINQ to SQL query in ASP.NET MVC and pass the JSON result to an EXT JS Combo box.

My Controller looks like this:

public ActionResult AllClients()
{
var clients = repo.GetAllClients();

return Json ( new { Data = clients }, JsonRequestBehavior.AllowGet);
}

My MVC Model method looks like this:

public IQueryable<Client> GetAllClients()
{
return contx.Clients;
}


My EXT JS Json Store Code looks like this:


var clientStore = new Ext.data.JsonStore({
url: '/GUIStuff/AllClients',
fields: ['ID', 'Name', 'Type'],
root: 'Data'
});

I know some have suggested not using IQueryable<> for JSON, but other say adding .ToList() solves any issues. I've tried this code with and without .toList() and the combo box does not populate.

When I evoke the JSON controller above, I get a JSON file in this format:

{"Data":[{"ID":1,"Name":"BeeBop","Type":"Pharm"},{"ID":2,"Name":"BopBee","Type":"Tox"},{"ID":3,"Name":"Ancillus","Type":"Tox"},{"ID":4,"Name":"Formosus","Type":"Pharm"},{"ID":5,"Name":"Randankle","Type":"Pharm"},{"ID":6,"Name":"Vorption","Type":"Tox"},{"ID":7,"Name":"Zequonquonk","Type":"Pharm"},{"ID":8,"Name":"Farrrf","Type":"Pharm"},{"ID":9,"Name":"Ardillo","Type":"Pharm"},{"ID":10,"Name":"Meson","Type":"Tox"},{"ID":11,"Name":"BeeBoopADoo","Type":"Pharm"},{"ID":12,"Name":"WhooEeeAWapp","Type":"Pharm"},{"ID":13,"Name":"ZipAHooHaaay","Type":"Pharm"},{"ID":14,"Name":"FFFeeeeetttt","Type":"Tox"},{"ID":15,"Name":"Yaaghaheee","Type":"Pharm"},{"ID":16,"Name":"Undulating","Type":"Tox"}]}

I did get one box to work that returned an array type with a container class, but using similar methods here ended up with squat.

Thank you!