Monday, January 28, 2013

Fill Dropdownlist in mvc


  @Html.DropDownListFor(m => m.categoryList, new SelectList(Model.categoryList, "Value", "Text"))

  public IEnumerable  categoryList { get; set; }
        KochiDealsEntities1 db = new KochiDealsEntities1();
        public IEnumerable fetchCategoryList()
        {
            var cat = (from m in db.ItemCategories
                       select new { m.CategoryID,m.CategoryName }).AsEnumerable().Select(x => new SelectListItem { Value = x.CategoryID.ToString(), Text = x.CategoryName, Selected = true  });
            return cat;
        }

No comments:

Post a Comment