我必须检查用户名和密码是否正确。所以我想将用户名和密码作为参数传递给控制器中的函数。我可以发送密码,但不能同时发送。
<div class="control-field">
<input type="text" id="ad-username" data-validation="required" data-validation-if-checked="isSecured" name="adusername" placeholder="AD Username"/>
</div>
<div class="control-field">
<input type="text" id="ad-password" data-validation="required server" name="adpassword" placeholder ="AD Password" data-validation-url="/FormValidation/CheckPassword" />
</div>
控制器 :
public JsonResult CheckPassword(string adusername, string adpassword) {
FormValidator validator = new FormValidator();
if (true) {
validator.valid = false;
validator.message = "User name and password did not match";
}
return Json(validator);
}
jQuery 验证:
$.validate(
{
modules: 'security',
form: '#existing-form',
validateOnBlur: false, // disable validation when input looses focus
errorMessagePosition: 'element', // Instead of 'element' which is default
scrollToTopOnError: false,// Set this property to true if you have a long form
language: {
requiredFields: "This field is required"
}
});