I'm having a problem with dropdownlist
. I populated it with information that was in my DB.
controller code:
public ActionResult NovoProduto()
{
ViewBag.categorias = new SelectList(db.Categoria, "CategoriaId", "Nome");
return View();
}
It loads into view all right. I'm getting in view this way:
@Html.DropDownList("categorias", "selecione uma categoria")
Only when I do an action, example, register a new product, and I have a return to the screen where the dropdownlist exists it gives error.
"{" There is no ViewData item of type 'IEnumerable' that has the 'Categories' key. "}"
I just have no idea why the error, because it does not change anything when it returns: I just added something to a table that has nothing to do with that of the list.