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>