我启用了不显眼的验证。我的页面源看起来像这样。
<p>
<label>
Project Title
<br />
<input class="project-title" data-val="true" data-val-required="The Project Title field is required."
id="RequestDetail_ProjectTitle" name="RequestDetail.ProjectTitle" type="text"
value="" />
</label>
<span class="field-validation-valid" data-valmsg-for="RequestDetail.ProjectTitle"
data-valmsg-replace="true"></span> </p> <p>
<span>Submitted By</span><br />
<span class="inline-container">
<input type="hidden" id="RequestDetail_SubmittedBy" name="RequestDetail.SubmittedBy"
value="0" data-type="RequestDetail.SubmittedBy" /><label><input type="radio" data-type="RequestDetail.SubmittedBy"
name="_RequestDetail.SubmittedBy" value="1" data-val="true" data-val-required="The Submitted By field is required." />ND</label>
|
<label>
<input type="radio" data-type="RequestDetail.SubmittedBy" name="_RequestDetail.SubmittedBy"
value="2" data-val="true" data-val-required="The Submitted By field is required." />NE</label>
|
<label>
<input type="radio" data-type="RequestDetail.SubmittedBy" name="_RequestDetail.SubmittedBy"
value="4" data-val="true" data-val-required="The Submitted By field is required." />WY</label>
|
<label>
<input type="radio" data-type="RequestDetail.SubmittedBy" name="_RequestDetail.SubmittedBy"
value="8" data-val="true" data-val-required="The Submitted By field is required." />CL</label>
</span><span class="field-validation-valid" data-valmsg-for="_RequestDetail.SubmittedBy"
data-valmsg-replace="true"></span> </p> <p>
<span>Affected Plans</span><br />
<span class="inline-container">
<input type="hidden" id="RequestDetail_AffectedPlans" name="RequestDetail.AffectedPlans"
value="0" data-type="RequestDetail.AffectedPlans" /><label><input type="checkbox"
data-type="RequestDetail.AffectedPlans" name="_RequestDetail.AffectedPlans" value="1"
data-val="true" data-val-required="The Affected Plans field is required." />ND</label>
|
<label>
<input type="checkbox" data-type="RequestDetail.AffectedPlans" name="_RequestDetail.AffectedPlans"
value="2" data-val="true" data-val-required="The Affected Plans field is required." />NE</label>
|
<label>
<input type="checkbox" data-type="RequestDetail.AffectedPlans" name="_RequestDetail.AffectedPlans"
value="4" data-val="true" data-val-required="The Affected Plans field is required." />WY</label>
</span><span class="field-validation-valid" data-valmsg-for="_RequestDetail.AffectedPlans"
data-valmsg-replace="true"></span> </p>
这是验证后的输出。
我使用单选按钮和此处显示的复选框以相同的方式应用了所有内容。但是为什么我在复选框中没有收到验证错误,而在单选按钮中却得到了我所期望的。