121

How do I access the ModelState from within my View (aspx page)?

Saajid Ismail
  • 7,551
  • 10
  • 45
  • 56

1 Answers1

189

Use ViewContext.ViewData.ModelState.

Abel
  • 54,106
  • 22
  • 138
  • 236
Mathias F
  • 15,202
  • 20
  • 87
  • 155
  • 21
    Also worthy to note that you can just do `ViewData.ModelState` and if you want to display some conditional markup on errors you can do like this: `@if (!ViewData.ModelState.IsValid)` – The Muffin Man Sep 15 '13 at 02:16