MVC Scaffolding error: "Value cannot be null. Parameter name: source"
Your problem is the following:
You assign this property within the Controller
:
ViewBag.PossibleCategory = context.Categories;
Then, in your View
you try to read this dynamic ViewBag
property:
ViewBag.PossibleCategories
Can you see the error? You're giving different names... You do not get compile time checking because ViewBag
uses the new C# 4 dynamic
type. ViewBag.PossibleCategories
will only be resolved at runtime. As there's no ViewBag
property that matches ViewBag.PossibleCategories
you get this error: Value cannot be null. Parameter name: source
To solve this just do this:
ViewBag.PossibleCategories = context.Categories;