C # ASP. NET MVC Annotation Validation

Source: Internet
Author: User

Look at the code, see the annotations, read the words, did not read the meaning.

We can only specialize in this feature today.

1. Remote

Looking at This example, I looked at the Jsonresult and Jsonrequestbehavior.allowget explained as follows

Http://www.cnblogs.com/lmfeng/p/3596175.html

Http://www.cnblogs.com/lushuicongsheng/archive/2012/07/31/2617032.html

2. Base and this

Access

The base keyword is used to access the members of the base class from a derived class: Calls a method on the base class that has been overridden by another method. Specifies the base class constructor that should be called when creating an instance of a derived class. Base class access can only be done in constructors, instance methods, or instance property accessors.

Base is commonly used to communicate with the base class when the derived class object is initialized.

base can access the public and protected members of the base class, and private members are inaccessible.

this refers to the class object itself, which accesses all constants, fields, properties, and method members of this class, regardless of the access level of the access element. Because this is only confined to the inside of the object, the outside of the object is not visible, this is the basic idea of this. In addition, a static member is not part of an object and therefore cannot be referenced in a static method.

• In multi-tier inheritance, there are two ways that a base can point to a parent class: First, if there is an overload, base will point to a method that inherits directly from the parent class member, such as the Showresult method in the Audi class, which is accessed using base car.showresult () method instead of accessing the Vehicle.showresult () method, but without overloading, base can point to either the public or protected methods of any parent class, such as the Audi class, which can use base to access the base class Vehicle.run () method. These we can use ILDasm.exe to get answers from the IL code.

• Try to use less or no base and this. In addition to the name collisions of the resolution subclasses and the invocation of other constructors in one constructor, the use of base and this is prone to unnecessary results.

• Using base and this in static members is not allowed. The reason is that both base and this access are instances of the class, that is, objects, and static members can only be accessed by the class and cannot be accessed by the object.

The base is designed to achieve polymorphism.

• You can specify only one constructor using the this or base keyword, which means that this and base cannot be combined on a single constructor.

• In simple terms, base is used to access overridden base class members in derived classes, and this is used to access members of this class, including inherited public and protected members, of course.

• In addition to base, another way to access the base class members is to implement the type conversions shown. Only the method cannot be a static method.

3, the necessity of the structure function

Class user{Public      string Createtime {get; private set;}      Public User ()      {this            . Createtime = DateTime.Now;      }} This simple example is when the new User () automatically generates a createtime. At the language level, you can simply not have any constructors, and then do this:
var user = new user (); user. Createtime = DateTime.Now;
The resulting user object is the same. But from a design aspect, the latter approach assigns the Createtime assignment to the caller, which relies on the "quality of the caller", for example, the caller does not know whether to assign a value to the field, or to assign the value arbitrarily, and so on. So it's very different.
4, Validation

The Validationresult class that represents the result of the ValidationRule return. Indicates whether the selected value passes the Validate method of the ValidationRule.

The ValidationRule class, which provides a way to create a custom rule to check the validity of user input.

An abstract modifier that indicates that the modified content is missing or not fully implemented.the abstract modifier is available for classes, methods, properties, indexers, and events. Use the abstract modifier in a class declaration to indicate that a class can be a base class only for other classes. A member that is marked as abstract or contained in an abstract class must be implemented by a class derived from an abstract class.

The Validationcontext class describes the classes that perform validation checks.

Validationcontext.displayname Gets or sets the name of the member to validate

C # ASP. NET MVC Annotation Validation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.