E
E
Easter2011-03-15 12:32:22
ASP.NET
Easter, 2011-03-15 12:32:22

How to make model validation representing a list of elements in ASP.NET MVC?

Tell me how you can make the validation of the model (on the form) which is a list of elements?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
Baileys, 2011-03-15
@Baileys


ASP.NET MVC 2 validation supports Data Annotations attributes. The attribute set is located in
System.ComponentModel.DataAnnotations, it has been present since ASP.NET 3.5 SP 1. By default, the
System.ComponentModel.DataAnnotations.dll assembly is added when creating an ASP.NET MVC 2 project, if it is not present, it
must be added manually.
List of validation attributes DataAnnotations:
RangeAttribute - indicates the limit of digital values ​​for the property;
RegularExpressionAttribute - indicates that the property must match the given regular expression;
StringLengthAttribute - specifies the maximum number of characters allowed in the property;
RequiredAttribute - indicates that the property is required;
Example:
public class Dinner {
[Required(ErrorMessage = "Title is required")]
public string Title {
get;
set;
}
}
[HttpPost]
public ActionResult Create(Dinner dinner) {
if(ModelState.IsValid) {
// Dinner is valid, save it.
}
else {
returnView();
}
}

E
eforce, 2011-03-16
@eforce

Here is a good article: ASP.NET MVC 2: Model Validation , in principle, this is one of the best sites for MVC.

A
Alexander Byndyu, 2012-05-29
@AlexanderByndyu

To set up validation, I would recommend MvcExtensions. Introduction blog.hazzik.ru/post/19465323230/mvcextensions-intro to the Metadata section.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question