Populating dropdownlist in asp.net mvc doesn't seem to work for me...
- by Pandiya Chendur
I use a dropdownlist in one of my create.aspx but it some how doesnt seem to work...
public IEnumerable<Materials> FindAllMeasurements()
{
var mesurements = from mt in db.MeasurementTypes
select new Materials()
{
Id= Convert.ToInt64(mt.Id),
Mes_Name= mt.Name
};
return mesurements;
}
and my controller,
public ActionResult Create()
{
var mesurementTypes = consRepository.FindAllMeasurements().AsEnumerable();
ViewData["MeasurementType"] = new SelectList(mesurementTypes, "Id", "Mes_Name");
return View();
}
and my create.aspx has this,
<p>
<label for="MeasurementTypeId">MeasurementType:</label>
<%= Html.DropDownList("MeasurementType", ViewData["MeasurementType"])%>
<%= Html.ValidationMessage("MeasurementTypeId", "*") %>
</p>
When i execute this i got these errors,
System.Web.Mvc.HtmlHelper<CrMVC.Models.Material>' does not contain a definition for 'DropDownList' and the best extension method overload 'System.Web.Mvc.Html.SelectExtensions.DropDownList(System.Web.Mvc.HtmlHelper, string, System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>)' has some invalid arguments
2.cannot convert from 'object' to 'System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>