Skip to content
This repository was archived by the owner on Oct 27, 2020. It is now read-only.

ValidateModelStateAttribute

Trevor Pilley edited this page Jan 5, 2015 · 1 revision

The ValidateModelStateAttribute validates the model state in a request and redirects to the view if it is invalid, it saves having to wrap all your methods with if (ModelState.IsValid()).

There are times when you may want to return a different model to the view than the one posted to the action so it is easy to opt out an action:

[ValidateModelState(SkipValidation = true)] // will only affect the action it is applied to
public ActionResult Edit(int id, Model model) { ... }

Clone this wiki locally