---
title: "Model require in mvc"  
description: "Model require in mvc"  
author: "Anonymous User"  
published: 2014-10-10  
updated: 2014-10-10  
canonical: https://www.mindstick.com/forum/2359/model-require-in-mvc  
category: "asp.net mvc"  
tags: ["asp.net", "asp.net mvc"]  
reading_time: 1 minute  

---

# Model require in mvc

Is there a way through [data annotations](https://www.mindstick.com/forum/160240/purpose-of-asp-dot-net-core-data-annotations) to require that a [boolean](https://www.mindstick.com/forum/160332/how-does-the-boolean-function-work) [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) be set to [true](https://yourviews.mindstick.com/view/81326/boycott-chinese-products-dream-will-come-true)?

```
public class MyAwesomeObj{    public bool ThisMustBeTrue { get; set; }}
```

## Replies

### Reply by Anonymous User

You could create your own validator:

```
public class IsTrueAttribute : ValidationAttribute        {            #region Overrides of ValidationAttribute            public override bool IsValid(object value)            {                if (value == null) return false;                if (value.GetType() != typeof(bool)) throw new InvalidOperationException("can only be used on
boolean properties.");                 return (bool)value == true;            }             #endregion        }
```


---

Original Source: https://www.mindstick.com/forum/2359/model-require-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
