swsh hussain

swsh hussain

  • NA
  • 11
  • 11.3k

getting error There is no ViewData item of type 'IEnumerab

Nov 17 2015 2:24 AM
 After clicking on create button without selecting any data  i got an error 
 
There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'CostCenterId'."}
 
this my contrller action  method
public ActionResult Create()
{
ViewBag.Currency = new SelectList(db.Currencys, "Id", "Currency");
ViewBag.CostCenterId = new SelectList(db.CostCenterIds, "Cost_Center_Id", "Cost_Center_Name");
return View();
}
 
 
<tr>
<td>
@Html.LabelFor(model => model.CostCenterId)
</td>
<td>
@Html.DropDownListFor(model => model.CostCenterId, (SelectList)ViewBag.CostCenterId, "Select ", new { style = "width:200px" })
@Html.ValidationMessageFor(model => model.CostCenterId)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(model => model.Currency)
</td>
<td>
@Html.DropDownListFor(model => model.Currency, (SelectList)ViewBag.Currency, "Select ", new { style = "width:200px" })
@Html.ValidationMessageFor(model => model.Currency)
</td>
</tr>
 

Answers (4)