Just learning about Validation, so I had defined a property on my model like this:

public string NumberOfThings { get; set; }

and a HTML for it like this:

  @Html.TextBoxFor(t => t.NumberOfThings , new {style = "width: 10%", @class = "form-control"})

Now I want to add validation to it, the data is saved as String in Database schema. My validation logic want it to say any number larger than 0 is OK.

So I learned about validation and that I can do things like this:

[StringLength(3, MinimumLength = 1)]
public string SelectedQuestions { get; set; }

and then was aboe to see that oh my ModelState is not valid.
But since I am new to this I couldn't figure out what is the correct validation I should annotate my property with so that it says any number larger than 0 is OK.

Related posts

Recent Viewed