I try to populate DropDownList from my database, but still have error
Cannon implicity convert type 'System.Web.Mvc.SelectList' to 'System.Collections.Generic.IEnumerable<MyWeb.Models.HomeViewModels.SelectListItem>'
My model:
public class BazarInsertViewModel
{
public int SelectedCategoryId { get; set; }
public IEnumerable<SelectListItem> MyCategory { get; set; }
}
public class SelectListItem
{
public string Value { get; set; }
public string Text { get; set; }
}
and my controller:
public ActionResult BazarInsert()
{
var model = new Models.HomeViewModels.BazarInsertViewModel
{
MyCategory = GetCategory()
};
return View(model);
}
private IEnumerable<Models.HomeViewModels.SelectListItem> GetCategory()
{
var dbo = new WebEntities();
var category = dbo
.bazar
.Select(x =>
new Models.HomeViewModels.SelectListItem
{
Value = x.ID.ToString(),
Text = x.TITLE
});
return new SelectList(category, "Value", "Text");
}
Please can you explain me what I'm doing wrong?