vendredi 22 avril 2016

Dijit Selects using Store in asp.net mvc3

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

    <div id="stateSelect"></div> 
    <script>
        dojo.require("dijit.form.Select");
        dojo.require("dojo.data.ItemFileReadStore");
        dojo.ready(function () {
            // create store instance referencing data from states.json
            var stateStore = new dojo.data.ItemFileReadStore({
                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");
            select.startup();

        });
    </script>

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