0

I am doing something of the sort:

return View("XXXXXX", new
        {
            Message = "ok"
        });

However when trying to read the variable via Model.Message an exception is thrown:

'object' does not contain a definition for 'Message'

Even though hovering on Model in the debugger shows Message = "ok"

Any Idea why this might be happening ?

Rudi Visser
  • 21,350
  • 5
  • 71
  • 97
Jonny
  • 2,787
  • 10
  • 40
  • 62

1 Answers1

1

As was mentioned in the comments, the trouble you're running into is that you're trying to use an anonymous type to pass through to the view. This means it will show up in your debugger, but your page will blow up, since it will interpret it as an object and not the type you're trying for.

The best solution for it would be to create a new Model class that has the Message property in it and to strongly type your View to that Model.

Corey Adler
  • 15,897
  • 18
  • 66
  • 80