jeudi 10 septembre 2015

Populate checkbox with data

i have a dropdown of car make,i want to populate checkbox with car models that depends onto the selected car make

 public JsonResult carmodelList(int Id)
        {

            var carmodel = from s in db.CarModel

                         where s.Make_id == Id

                         select s;

            return Json(new SelectList(carmodel.ToArray(), "Model_id", "ModelName"), JsonRequestBehavior.AllowGet);

        }

        public IList<CarModel> Getmodel(int Model_id)
        {

            return db.CarModel.Where(m => m.Model_id == Model_id).ToList();

        }
        [AcceptVerbs(HttpVerbs.Get)]

        public JsonResult LoadClassesBymake_id(string MakeName)
        {

            var carmodelList = this.Getmodel(Convert.ToInt32(MakeName));

            var carmodelData = carmodelList.Select(m => new SelectListItem()

            {

                Text = m.ModelName,

                Value = m.Make_id.ToString(),

            });

            return Json(carmodelData, JsonRequestBehavior.AllowGet);

        }
     public JsonResult carmodelList(int Id)
        {

            var carmodel = from s in db.CarModel

                         where s.Make_id == Id

                         select s;

            return Json(new SelectList(carmodel.ToArray(), "Model_id", "ModelName"), JsonRequestBehavior.AllowGet);

        }

        public IList<CarModel> Getmodel(int Model_id)
        {

            return db.CarModel.Where(m => m.Model_id == Model_id).ToList();

        }
        [AcceptVerbs(HttpVerbs.Get)]

        public JsonResult LoadClassesBymake_id(string MakeName)
        {

            var carmodelList = this.Getmodel(Convert.ToInt32(MakeName));

            var carmodelData = carmodelList.Select(m => new SelectListItem()

            {

                Text = m.ModelName,

                Value = m.Make_id.ToString(),

            });

            return Json(carmodelData, JsonRequestBehavior.AllowGet);

        }

<!-- begin snippet: js hide: false -->



Aucun commentaire:

Enregistrer un commentaire