Populating dropdownlist in asp.net mvc doesn't seem to work for me...
Posted
by Pandiya Chendur
on Stack Overflow
See other posts from Stack Overflow
or by Pandiya Chendur
Published on 2010-05-03T05:04:05Z
Indexed on
2010/05/03
5:08 UTC
Read the original article
Hit count: 292
asp.net-mvc
|dropdownlist
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>
© Stack Overflow or respective owner