asp.net mvc 3 jquery validate를 사용하여 등록 양식을 만들어야합니다. UI 및 탐색 스타일로 인해 3 개의 JS 탭으로 분할 된 약 20 개의 필드로 구성됩니다. 나는 프로파일 모델에 주석을 통해 서버 측에 내 모든 검증을 썼다 :ASP.NET MVC 3 클라이언트 측 유효성 검사 3 탭 양식
namespace Web.Models
{
public class ProfileModel
{
//companyName
[Required(ErrorMessageResourceType = typeof(Core.Resources.Resources),
ErrorMessageResourceName = "CompanyNameRequired")]
[StringLength(50, ErrorMessageResourceType = typeof(Core.Resources.Resources),
ErrorMessageResourceName = "CompanyNameLong")]
[Display(Name = "CompanyName_label")]
public string companyName { get; set; }
//companyAddress
[Required(ErrorMessageResourceType = typeof(Core.Resources.Resources),
ErrorMessageResourceName = "CompanyAddressRequired")]
[StringLength(50, ErrorMessageResourceType = typeof(Core.Resources.Resources),
ErrorMessageResourceName = "CompanyAddressLong")]
[Display(Name = "CompanyAddress_label")]
public string companyAddress { get; set; }
//companyCity
[Required(ErrorMessageResourceType = typeof(Core.Resources.Resources),
ErrorMessageResourceName = "CompanyCityRequired")]
[StringLength(50, ErrorMessageResourceType = typeof(Core.Resources.Resources),
ErrorMessageResourceName = "CompanyCityLong")]
[Display(Name = "CompanyCity_label")]
public string companyCity { get; set; }
//companyZip
[Required(ErrorMessageResourceType = typeof(Core.Resources.Resources),
ErrorMessageResourceName = "CompanyZipRequired")]
[StringLength(10, ErrorMessageResourceType = typeof(Core.Resources.Resources),
ErrorMessageResourceName = "CompanyZipLong")]
[Display(Name = "CompanyZip_label")]
public string companyZip { get; set; }
... and so on for a toltal 20 fields ...
내 검증 라벨은 우리의 코어 -> 리소스 지역화 파일에이 프로필 컨트롤러는 HTTPPOST를 잡기 위해 코딩과 내 생각은 다음과 같습니다 :
@model Web.Models.ProfileModel
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@Html.ValidationSummary(true)
@using (Html.BeginForm("Register", "Profile", FormMethod.Post, new { id = "RegForm" }))
{
<div id="tabs">
<ul>
<li><a href="#tabs-1">Company</a></li>
<li><a href="#tabs-2">User</a></li>
<li><a href="#tabs-3">Address</a></li>
</ul>
<fieldset>
<div id="tabs-1">
<div class="editor-label">
@Html.LabelFor(model => model.companyName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.companyName)
@Html.ValidationMessageFor(model => model.companyName)
</div>
... here other fields ...
</div>
<div id="tabs-2">
<div class="editor-label">
@Html.LabelFor(model => model.userFName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.userFName)
@Html.ValidationMessageFor(model => model.userFName)
</div>
... here other fields ...
당신은 내가 정의 된 모든 필드, 3 개 탭 (회사, 사용자, 주소)를 통해 스플릿 하나의 "큰"양식 단일 ProfileModel을 사용하여 볼 수 있듯이. 이제 첫 번째 탭의 맨 아래에 다음 버튼, 두 번째 탭의 맨 아래에있는 PREV 및 NEXT 버튼, 마지막으로 세 번째 및 마지막 탭의 맨 아래에있는 PREV 및 SUBMIT 버튼을 놓아야합니다.
제 질문은 tab1이 유효성이 검사되지 않더라도 (부분 유효성 검사) 사용자가 tab2로 건너 뛰지 않도록 클라이언트 측 스크립팅을 구현하는 방법입니다. 이전 탭의 유효성을 올바르게 검사 한 경우에만 탭을 검색해야합니다. 아이디어가 있으십니까?
ShaneC에게 감사드립니다. Razor는 아니지만 게시글은 필드가 포커스가 맞았을 때 필드에서 유효성 검사를 수행하는 방법을 보여줍니다. 게다가 내 모델의 부분 유효성 검사를 수행해야하지만 각 단일 필드에 대한 모델 유효성 검사 규칙은 유지해야합니다. 고마워. – User907863
http://bit.ly/fK7bXz도 참조하십시오. – user571646