뷰 모델의 하위 개체에 대한 클라이언트 측 유효성 검사 -MVC 3 -이 보이는 뷰 모델이
public class upgradeViewModel
{
public Cart Cart { get; set; }
public RegisterModel RegisterModel { get; set; }
}
뷰 모델은 RegisterModel
모델 객체가이 비슷합니다 RegisterModel
라는 속성이 포함 -
public class RegisterModel
{
[Required]
[Display(Name = "Your name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
[Display(Name = "Your email address")]
public string Email { get; set; }
...
}
나는 모델의로 upgradeViewModel
개체를 사용하는보기에서 폼을 설정하는 뷰 모델에 RegisterModel
속성을 사용합니다. 양식을 제출할 때 어떤 클라이언트 측 유효성 검사도 수행하지 않지만 RegisterModel
개체에 대해 서버 측 유효성 검사를 수행합니다.
저는 모든 작업에 눈에 띄지 않는 클라이언트 측 유효성 검사가 올바르게 구성되어 있고 웹 사이트의 다른 영역에서 작동한다고 생각합니다. 뷰 모델의 자식 객체에서 작동하도록 클라이언트 측 유효성 검사를 수행하려면 추가 작업이 필요합니까?
이@model upgradeViewModel
@{
ViewBag.Title = "Title";
Layout = "~/Views/Shared/_LayoutNormal.cshtml";
}
<h2>Title</h2>
Some text ....
@using (Html.BeginForm()) {
@Html.ValidationSummary(true, "Account creation was unsuccessful. Please correct the errors and try again.")
<div>
<fieldset>
<legend>Your Information</legend>
<div class="editor-label">
@Html.LabelFor(m => m.RegisterModel.UserName)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.RegisterModel.UserName)
@Html.ValidationMessageFor(m => m.RegisterModel.UserName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.RegisterModel.Email)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.RegisterModel.Email)
@Html.ValidationMessageFor(m => m.RegisterModel.Email)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.RegisterModel.Password)
</div>
<div class="editor-field">
@Html.PasswordFor(m => m.RegisterModel.Password)
@Html.ValidationMessageFor(m => m.RegisterModel.Password)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.RegisterModel.ConfirmPassword)
</div>
<div class="editor-field">
@Html.PasswordFor(m => m.RegisterModel.ConfirmPassword)
@Html.ValidationMessageFor(m => m.RegisterModel.ConfirmPassword)
</div>
<p>
<input type="submit" value="Save Details" class="inputbutton" />
</p>
</fieldset>
</div>
}