@using (Ajax.BeginForm()) 내에 passwordFor, oldpassword, newpassword 및 confirmnewpassword 세 개가 있습니다.) {---}, 나는이 값을 모델로 묶어야하고 데이터 주석을 사용하여 클라이언트 측에서 검증 된 newpassword 및 confirmnewpassword 값이 필요합니다. newpassword와 confirmnewpassword의 값을 비교하기 위해 [Compare ("newpassword", errormessage = "오류 메시지 ---"()를 사용했습니다. .] 완벽하게 작동하지만 oldpassword에 대한 암호도 Ajax.BeginForm 내부에서 가져온 경우 비교 유효성 검사가 작동하지 않습니다. 모델을 통해 내 컨트롤러에 전달할이 세 값이 모두 필요하며이 세 개의 상자를 사용할 수 없습니다. newpassword와 confirmnewpassword를 비교하는 동일한 형식 oldpassword가 BeginForm() 외부에서 가져온 경우 compare는 작동하지만 oldpassword의 값은 데이터 주석을 사용하여 유효성이 검사되지 않고 그 값이 모델을 통해 컨트롤러로 전달되지 않습니다. 전체 I 이 Ajax.BeginForm 내에서이 세 가지 PasswordFor가 모두있는 동안이 [Compare()] 작업을 수행해야하며 모든 유효성 검사가 완료 될 때까지 제출되지 않습니다. 클라이언트 측에서 검증되었습니다. 도움이 될 것입니다.MVC3에서 데이터 주석을 사용하는 동안 [Compare ("", ..)]를 사용하여 새 암호 비교 및 새 암호 확인을 수행하지 못함
내보기 :
@model eremit.Models.CustomerAll
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftAjax.debug.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.debug.js")" type="text/javascript"></script>
@using (Ajax.BeginForm("verifycustomer", "CustomerLogin", new AjaxOptions { UpdateTargetId = "messagediv" }))
{
@Html.ValidationSummary(true)
<h3>Old password</h3>@Html.PasswordFor(model => model.Login.oldpassword)
@Html.ValidationMessageFor(model => model.Login.oldpassword)
<h3>New password</h3>@Html.PasswordFor(model => model.Login.newpassword)
@Html.ValidationMessageFor(model => model.Login.newpassword)
<h3>
Re-enter New password</h3>@Html.PasswordFor(model => model.Login.confirmnewpassword)
@Html.ValidationMessageFor(model => model.Login.confirmnewpassword)
<div id="messagediv">
</div>
<input type="submit" id="btnchangepassword" value="Change Password" />
내 모델 :
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc;
using System.Web.Security;
namespace eremit.Models
{
public class Login
{
[Required(ErrorMessage = "* Please enter old password")]
public string oldpassword { get; set; }
[Required(ErrorMessage = "* Please enter new password")]
[Display(Name = "newpassword")]
[RegularExpression("^[a-zA-Z<>[email protected]#!%&_0-9]+$", ErrorMessage = "Invalid Password")]
public string newpassword { get; set; }
[Required(ErrorMessage = "* Re-enter your new password")]
[Compare("newpassword", ErrorMessage = "The new password and confirmation password do not match.")]
public string confirmnewpassword { get; set; }
}
}