0

So I have a question about model in ASP.NET MVC. I know I can use a ViewBag like this: <h1> @ViewBag.Question </h1> and it would display the text in @ViewBag.Question. Can I use @model in the same way? I have tried using it in the same context, <h1> @Model.Question </h1> but the view throws an error. How can I display the text of a model property inside an html element?

perennial_
  • 1,798
  • 2
  • 26
  • 41
  • İf your model has a property for Question then you can .What is the error meanwhile? – Mustafa ASAN Jul 27 '15 at 18:43
  • I'm a moron, I forgot to actually pass the model to the view. I just assumed because I was trying something new it was that that broke it. – perennial_ Jul 27 '15 at 19:44
  • possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) –  Jul 27 '15 at 23:07

1 Answers1

0

Yes, @Model can be used in the same way as @ViewBag

perennial_
  • 1,798
  • 2
  • 26
  • 41