vendredi 22 avril 2016

Dijit Selects using Store in mvc3

I want to use Selectlist Dijit load data from SQL, i use Dojo + MVC3, my code looks like the follow, but i don't know why my code isn't working. On view:

    <div id="stateSelect"></div> 
        dojo.ready(function () {
            // create store instance referencing data from states.json
            var stateStore = new{
                url: "/Home/GetHuyenTP"
            // create Select widget, populating its options from the store
            var select = new dijit.form.Select({
                name: "stateSelect",
                store: stateStore,
                maxHeight: -1 
            }, "stateSelect");


On HOmecontroller

    public JsonResult GetHuyenTP()
        hmodel.GetListHuyenTp(); //it is List<SelectListItem>           
        var jSonData = new
            identifier = "Value", 
            label = "Text",
            items = hmodel.ListHuyenTp.ToArray()
        return Json(jSonData);

The struct of json looks like

   "identifier": "abbreviation",
   "label": "name",
   "items": [
       { "abbreviation": "AL", "name": "Alabama" },
        ... other 48 states here ...
       { "abbreviation": "WY", "name": "Wyoming" }

Can you help me? Thank you very much.

Aucun commentaire:

Enregistrer un commentaire