I created a C# Razor site with no explicit model definitions, relying on the dynamic keyword to represent my model. However, this is now breaking because it says that “object doesn’t contain member X”. It does contain it; intellisense shows this, but whatever is using the model, when dynamic, is breaking. Even adding @model dynamic doesn’t work.
Changing to an explicit model is working, so I’m doing that, but what would cause dynamic support to stop working in process?
EDIT:
My controller simply does this:
public ActionResult List()
{
return View(new
{
Data = repos.GetData()
});
}
and the uses it directly:
@{ Title = "X" }
@foreach (var item in Model.Data)
{
Render
}
The model and data is not null, and there is valid data.
Thanks.
If you want to utilize dynamic types to be passed, you should use the
ViewBagproperty. Your code could read:Your View:
I tried to get your code working but I also throw the same error.