Remote usage in MVC and remote usage in mvc

Source: Internet
Author: User

Remote usage in MVC and remote usage in mvc

1. Add web. config
<Deleetask>
<Add key = "ClientValidationEnabled" value = "true"/>
<Add key = "UnobtrusiveJavaScriptEnabled" value = "true"/>
</AppSettings>

Ii. Controllers Verification Method
Using System;
Using System. Globalization;
Using System. Web. Mvc;
Using System. Web. UI;
Using Mvc3RemoteVal. Models;

Namespace Mvc3RemoteVal. Controllers {
Public class ValidationController: Controller {

/// <Summary>
/// Check whether the seller's nickname already exists
/// </Summary>
/// <Param name = "sellerNick"> nickname </param>
/// <Returns> bool </returns>

[OutputCache (Location = OutputCacheLocation. None, NoStore = true)] // clear the cache

Public JsonResult CheckSellerNick (string sellerNick)
{
Bool isValidate = false; // true indicates that the specified parameter does not exist. false indicates that the specified parameter exists.
If (! SellerAccess. CheckSellerNick (sellerNick ))
{
IsValidate = true;
}
Return Json (isValidate, JsonRequestBehavior. AllowGet );

}

}
}
Iii. model
Public class UserModel {
[Required]
[StringLength (6, MinimumLength = 3)]
[Remote ("CheckSellerNick", "Validation", ErrorMessage = "this nickname already exists")] // ActionName, Controller, error message
[Editable (true)]
Public override string UserName {get; set ;}
}

Iv. View reference
<Script src = "@ Url. Content ("~ /Scripts/jquery-1.7.1.js ")"> </script>
<Script src = "@ Url. Content ("~ /Scripts/jquery. validate. min. js ")"> </script>
<Script src = "@ Url. Content ("~ /Scripts/jquery. validate. unobtrusive. min. js ")"> </script>

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.