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

ValidateModelNotNullAttribute

Trevor Pilley edited this page May 20, 2014 · 1 revision

The ValidateModelNotNullAttribute will throw an ArgumentNullException if the model in a request is null, it saves having to write if (model == null) { throw new ArgumentNullException("model"); } at the start of every action.

You may not want the attribute to apply to a certain action, therefore the ValidateModelNotNullAttribute has a SkipValidation property (false by default) which allows you to opt out individual actions.

[ValidateModelNotNull(SkipValidation = true)] // will only affect the action it is applied to
public HttpResponseMessage Edit(int id, Model model) { ... }
Clone this wiki locally