DropdownList with BeginCollectionItem

1

Good Night!

I could follow in this same question here

asked by anonymous 01.05.2017 / 02:49

2 answers

3

You have not set ViewBag to return from Partial . Of course there will be a zero reference error:

public ActionResult NovaLinhaDeTipoDeLixo()
{
    ViewBag.Lixo = db.TiposDeLixo.ToList();
    return PartialView("_LinhaTipoDeLixo", new PontoDeColetaTipoDeLixo { Id = Guid.NewGuid() });
}
    
07.05.2017 / 00:31
1

Hello, change your code as follows:

@Html.ListBox("Id", new SelectList((List<SeuNamespace.Lixo>)ViewBag.Lixo))

I hope I have helped.

    
05.05.2017 / 21:30