---
title: "What is DataAnnotations in mvc?"  
description: "What is DataAnnotations in mvc?"  
author: "Anonymous User"  
published: 2014-10-09  
updated: 2014-10-09  
canonical: https://www.mindstick.com/forum/2345/what-is-dataannotations-in-mvc  
category: "asp.net mvc"  
tags: ["asp.net", "asp.net mvc"]  
reading_time: 1 minute  

---

# What is DataAnnotations in mvc?

Here is a [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) "Cars" and I have 2 attributs (min/[max](https://www.mindstick.com/articles/1155/count-max-min-function-in-excel) CO2).

```
public class Cars        {            [Range("MinCO2", int.MaxValue, ErrorMessage = "MaxCO2 < MinCO2")]            public int MaxCO2 { get; set; }            [Range(0, "MaxCO2", ErrorMessage = "MaxCO2 > MinCO2")]            public int MinCO2 { get; set; }        }
```

I use the [Data Annotation](https://www.mindstick.com/articles/12234/validation-using-data-annotation-using-entity-framework) '[Range](https://www.mindstick.com/articles/23243/complete-troubleshooting-tips-for-belkin-n300-range-extender-setup)' to [fix](https://yourviews.mindstick.com/view/80763/donald-trump-ki-jeet-fix-hai) the minimum and the [maximum value](https://www.mindstick.com/forum/33667/select-the-maximum-value-of-a-colum-in-mysql).

But I want to use the car's attribut to fix the minimum or the maximum value.

Or if there is another solution with jQuery, it can be possible.

## Replies

### Reply by Anonymous User

Try this

Send Mininum value and Maximum value from Controller to View using Model or ViewBag/ViewData.

```
ViewBag.Min = 0;ViewBag.Max = Int32.MaxValue;
```

\
In View use jQuery validation to specify min and max validation using passed values. View.

```
<script language="javascript">    var mi="@ViewBag.Min";    var mx="@ViewBag.Max";    $(document).ready(function(){        $('#myform').validate({            rules:{                field:{                    required: true,                    min: mi,                    max:mx,                }            };        });    });</script>
```


---

Original Source: https://www.mindstick.com/forum/2345/what-is-dataannotations-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
