Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Can I take advantage of ASP.NET MVC model validation features (for example using [StringLength(n)] and other validation attributes on model class properties) without using Entity Framework? I want to gain the benefit of this validation functionality during model binding but I want to use a different ORM for my data access.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Model validation features such as StringLengthAttribute are attributes in the System.ComponentModel.DataAnnotations namespace and have nothing to do with the Entity Framework. Just add the attribute to a property in your view model. For example

public class MyModel
{
  [StringLength(10, ErrorMessage="The name must be at least {1} characters"))]
  public string Name { get; set; }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.