The problem is after posting data, you are returning the View but you are not populating
ViewBag values. So when it executes
DropDownListFor() helper in View, it throws exception as
ViewBag.DaneKont is not set from action so it will be null, In your post action you need to add following code again before returning View, so that
ViewBag values are available:
context2.SaveChanges();
}
List<SelectListItem> items = new List<SelectListItem>();
foreach (var item in konto)
{
items.Add(new SelectListItem
{
Text = item.Nazwa+ " Saldo :"+item.Saldo ,
Value = item.KontoId+""
});
}
ViewBag.DaneKont = items;
SelectList selectList = new SelectList(items, "Value", "Text");
ViewBag.DaneKontList = selectList;
return View();
}