Click here to Skip to main content
15,179,246 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
actually i want to use viewbag to create a dropdownlist

in controller
public ActionResult Index()
          var par = (from d in _db.DTypes
                     select new ArticleRepository {  dtype = d }).First();
          var query = _db.DTypes.Select(c => c.DataType);
          //var query = from tbl in _db.DTypes
          //            join tb in _db.ParamDtypes on tbl.DataId=tbl.DataId
          //            select new SelectListItem(tbl.DataType).;
          ViewBag.DTypes = new SelectList(query.AsEnumerable());
          return View();

in view page

@Html.DropDownListFor(model => model.ddlStateId,IEnumerable<SelectListItem>>ViewBag.DTypes,"")
    @Html.ValidationMessageFor(model => model.ddlStateId)

now what i want to do is when i select the text as cat in dropdownlist then i have to pass id of that cat?
how can i do that ?
Updated 1-Mar-12 21:01pm

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900