четверг, 14 марта 2013 г.

Removing implicit validation

Assume that we have a model
public class Order
{
    [DisplayName("Purpose")]
    public string purpose { get; set; }

    [DisplayName("Tasks")]
    public string tasks { get; set; }
}
As we can see none of these fields have "Reguired" attribute. Any when you look at HTML source code in you browser you could find: data-val-required="The Purposefield is required." To remove this attribute just add the line into Application_Start method in Global.asax.cs file:
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;

Комментариев нет: