dynamitey and dynamic MVC models

So today I’m building out my new MVC application and get to writing this small block of code

  return View(new { Items = model });

ANDDD

Server Error in ‘/’ Application.


‘object’ does not contain a definition for ‘Items’

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ‘object’ does not contain a definition for ‘Items’

Apparently what I want to do is literally impossible. Ironically I had already commented on one of these answers.

Eventually the rabbit hole leads me to dynamitey (github)   and now I can do:

  return View(Build<ExpandoObject>.NewObject(Items: model });

 

Advertisements