Remote attribute in MVC5

As we know we have different types of attributes in MVC5 .

1. Binding Attribute.
2. Handle Error  attribute
3. Remote attribute 
4. Hidden Input attribute.

In this Tips we will discuss about the Remote attribute. Let me give you an example.

Basically When you we register  a user details or when we open a new account in google we check that given email is exits previously or not . If the given email is exists then a error message is appeared like "The given email is exits .Please provide a different one." . So this email checking is happening without any Form Post request . So this type of request can be handled by "Remote attribute" in MVC5.

Lets take an example here .

We can apply to an Model property like in our case Email property.
    
 public class User
{
    public string Name { get; set; }
    [Remote("CheckEmail","User",ErrorMessage="Email is already exist")]
    public string Email { get; set; }
    public string Address { get; set; }
    public string PhoneNo { get; set; }
}

In this above example Remote attribute "CheckEmail" is Action Name.
                                                                  "User"    is Controller Name.
                                                                  "ErrorMessage" is designed to show the error message.

whenever user will enter an email in email text box, CheckEmail ActionMethod will get called and check whether email exists or not.

 public JsonResult CheckEmail(string Email)
  {
      //Check here in database if it exist in database return true else false.
      return Jsonobject.
  }

Enjoy guys . Do not forget to like this if it is helpful. 

Comments

Popular posts from this blog

The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

The transaction is aborted or Failure while attempting to promote transaction.

Unable to load one or more breakpoints in Visual studio.