MVC3 と razaor ビュー エンジンを使用しています
パスワードと確認パスワードが一致することを確認しようとしていますが、うまくいきません。「パスワード」と「パスワードの確認」が一致しないと何度も言われます。
「compare」と「equalto」を使用しましたが、どちらも同じエラーになります。
事業体:
namespace Project.BusinessEntities
{
public partial class RegisterPasswordUpdate
{
public string Password { get; set; }
public string ConfirmPassword { get; set; }
public string UserId { get; set; }
}
}
検証:
using System.ComponentModel.DataAnnotations;
using DataAnnotationsExtensions;
using System.Web.Mvc;
using Project.Resources;
namespace Project.BusinessEntities
{
[MetadataType(typeof(RegisterPasswordUpdate.RegisterPasswordUpdateMetaData))]
public partial class RegisterPasswordUpdate
{
public class RegisterPasswordUpdateMetaData
{
[Required(ErrorMessage = ValidationMessageConstants.ResponseRequired)]
[StringLength(16, MinimumLength = 8)]
[RegularExpression(@"[A-Za-z0-9]*", ErrorMessage = ValidationMessageConstants.AlphaNumericOnly)]
public string Password { get; set; }
[Required(ErrorMessage = ValidationMessageConstants.ResponseRequired)]
[StringLength(16, MinimumLength = 8, ErrorMessage = ValidationMessageConstants.MinimumLength)]
[RegularExpression(@"[A-Za-z0-9]*", ErrorMessage = ValidationMessageConstants.AlphaNumericOnly)]
[EqualTo("Password", ErrorMessage = ValidationMessageConstants.ConfirmPassword)]
public string ConfirmPassword { get; set; }
}
}
}
使用する:
@Html.TextBoxFor(x => x.PasswordUpdate.Password, new { maxlength = "16", size = "16" })
@Html.ValidationMessageFor(x => x.PasswordUpdate.Password)
@Html.TextBoxFor(x => x.PasswordUpdate.ConfirmPassword, new { maxlength = "16", size = "16" })
@Html.ValidationMessageFor(x => x.PasswordUpdate.ConfirmPassword)
html:
<input data-val="true" data-val-length="The field Password must be a string with a minimum length of 8 and a maximum length of 16." data-val-length-max="16" data-val-length-min="8" data-val-regex="Only alphanumeric (A-Z a-z 0-9) values are allowed" data-val-regex-pattern="[A-Za-z0-9]*" data-val-required="Response required!" id="PasswordUpdate_Password" maxlength="16" name="PasswordUpdate.Password" size="16" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="PasswordUpdate.Password" data-valmsg-replace="true"></span>
<input data-val="true" data-val-equalto="Password and confirm password do not match" data-val-equalto-other="*.Password" data-val-length="Minimum length not met" data-val-length-max="16" data-val-length-min="8" data-val-regex="Only alphanumeric (A-Z a-z 0-9) values are allowed" data-val-regex-pattern="[A-Za-z0-9]*" data-val-required="Response required!" id="PasswordUpdate_ConfirmPassword" maxlength="16" name="PasswordUpdate.ConfirmPassword" size="16" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="PasswordUpdate.ConfirmPassword" data-valmsg-replace="true"></span>
ページの html ID:
PasswordUpdate_Password PasswordUpdate_ConfirmPassword
ページ上の html 名:
PasswordUpdate.Password PasswordUpdate.ConfirmPassword
ここに何が欠けていますか?