我并不想花时间进行客户端验证。也许对于未来的项目,但我只想对我的表单进行一些基本的表单验证......
我知道您可以将这些东西链接到您的模型或其他任何东西,但如果他的输入不正确,我真的只想向客户显示一条错误消息。但是,我很难得到任何验证。所以我想我错过了一些相当简单的东西。我以为我已经覆盖了所有的基础,但显然没有。
这是我包含在项目和视图中的脚本...
<script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.unobtrusive.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.maskedinput-1.3.min.js" type="text/javascript"></script>
我不认为有错误,因为屏蔽的输入正在工作......但我真的应该打开我的调试器以确保。我会尽快完成这篇文章。
这是我正在做一些一般性验证的地方......
$("eEncId").validate({
rules: {DateOfBirth: {
required: true
}
}
})
无论我是否有出生日期,表格似乎都提交了......我错过了什么?
更新:发布 html 输出...
<form action="/EditEncounter/Save?popid=2" id="eEncId" method="post"><label for="Active">Deactivate</label><input id="Active" name="Active" type="radio" value="N" /><input data-val="true" data-val-number="The field EncounterId must be a number." data-val-required="The EncounterId field is required." id="EncounterId" name="EncounterId" type="hidden" value="1898" /><input data-val="true" data-val-number="The field EMPIID must be a number." data-val-required="The EMPIID field is required." id="EMPIID" name="EMPIID" type="hidden" value="0" /><input data-val="true" data-val-number="The field PatientId must be a number." data-val-required="The PatientId field is required." id="PatientId" name="PatientId" type="hidden" value="4433" /> <table width="500" class="odd">
<tr><td>
<label for="FirstName">FirstName</label>
</td>
<td><input Value="RAYFIELD" id="FirstName" name="FirstName" type="text" value="RAYFIELD" /></td>
</tr>
<tr><td>
<label for="LastName">LastName</label>
</td>
<td>
<input Value="BOYD" id="LastName" name="LastName" type="text" value="BOYD" />
</td>
</tr>
<tr><td>
<label for="DateOfBirth">DateOfBirth</label>
</td>
<td>
<input Value="03/06/1947 00:00:00" data-val="true" data-val-date="The field DateOfBirth must be a date." id="DateOfBirth" name="DateOfBirth" type="text" value="3/6/1947 12:00:00 AM" />
</td>
</tr>
<tr><td>
<label for="Phone">Phone</label>
</td>
<td>
<input Value="4124880798" id="Phone" name="Phone" type="text" value="4124880798" />
</td></tr>
<tr><td>
<label for="HostpitalFinNumber">HostpitalFinNumber</label>
</td>
<td>
<input Value="6669511596226" id="HostpitalFinNumber" name="HostpitalFinNumber" type="text" value="6669511596226" />
</td></tr>
<tr><td>
<label for="AdminDate">AdminDate</label>
</td>
<td>
<input Value="03/02/2012 00:00:00" data-val="true" data-val-date="The field AdminDate must be a date." id="AdminDate" name="AdminDate" type="text" value="3/2/2012 12:00:00 AM" />
</td></tr>
<tr><td>
<label for="MRNType">MRNType</label>
</td>
<td>
<input Value="MPACMRN" id="MRNType" name="MRNType" type="text" value="MPACMRN" />
</td></tr>
<tr><td>
<label for="MRN">MRN</label>
</td>
<td>
<input Value="785528039" id="MRN" name="MRN" type="text" value="785528039" />
</td></tr>
<tr><td>
<label for="PatientRoomPhone">PatientRoomPhone</label>
</td>
<td>
<input Value="" id="PatientRoomPhone" name="PatientRoomPhone" type="text" value="" />
</td></tr>
<tr><td>
<label for="DischargeDateTime">DischargeDateTime</label>
</td>
<td>
<input Value="01/01/0001 00:00:00" data-val="true" data-val-date="The field DischargeDateTime must be a date." id="DischargeDateTime" name="DischargeDateTime" type="text" value="1/1/0001 12:00:00 AM" />
</td></tr>
<tr><td>
<label for="DischargeDisposition">DischargeDisposition</label>
</td>
<td>
<input Value="" id="DischargeDisposition" name="DischargeDisposition" type="text" value="" />
</td></tr>
<tr><td>
<label for="DischargeTo">DischargeTo</label>
</td>
<td>
<input Value="" id="DischargeTo" name="DischargeTo" type="text" value="" />
</td></tr>
<tr><td>
<label for="DischargeAdvocateCall">DischargeAdvocateCall</label>
</td>
<td>
<input Value="" id="DischargeAdvocateCall" name="DischargeAdvocateCall" type="text" value="" />
</td></tr>
<tr><td>
<label for="Payor">Payor</label>
</td>
<td>
<input Value="" id="Payor" name="Payor" type="text" value="" />
</td></tr>
<tr><td>
<label for="HomeHealthCareAccepted">HomeHealthCareAccepted</label>
</td>
<td>
<input Value="" id="HomeHealthCareAccepted" name="HomeHealthCareAccepted" type="text" value="" />
</td></tr>
<tr><td>
<label for="SafeLandingAccepted">SafeLandingAccepted</label>
</td><td>
<input Value="" id="SafeLandingAccepted" name="SafeLandingAccepted" type="text" value="" />
</td></tr>
<tr><td>
<label for="PCPName">PCPName</label>
</td><td>
<input Value="Dr. Peggy Halsey" id="PCPName" name="PCPName" type="text" value="Dr. Peggy Halsey" />
</td></tr>
<tr><td>
<label for="PCPPhone">PCPPhone</label>
</td><td>
<input Value="4126244141" id="PCPPhone" name="PCPPhone" type="text" value="4126244141" />
</td></tr>
<tr><td>
<label for="SpecialistName">SpecialistName</label>
</td><td>
<input Value="" id="SpecialistName" name="SpecialistName" type="text" value="" />
</td></tr>
<tr><td>
<label for="SpecialistPhone">SpecialistPhone</label>
</td><td>
<input Value="" id="SpecialistPhone" name="SpecialistPhone" type="text" value="" />
</td></tr>
<tr><td>
<label for="PCPAppointmentDateTime">PCPAppointmentDateTime</label>
</td><td>
<input Value="01/01/0001 00:00:00" data-val="true" data-val-date="The field PCPAppointmentDateTime must be a date." id="PCPAppointmentDateTime" name="PCPAppointmentDateTime" type="text" value="1/1/0001 12:00:00 AM" />
</td></tr>
<tr><td>
<label for="PCPAppointmentLocation">PCPAppointmentLocation</label>
</td><td>
<input Value="" id="PCPAppointmentLocation" name="PCPAppointmentLocation" type="text" value="" />
</td></tr>
<tr><td>
<label for="SpecialistAppointmentDateTime">SpecialistAppointmentDateTime</label>
</td><td>
<input Value="01/01/0001 00:00:00" data-val="true" data-val-date="The field SpecialistAppointmentDateTime must be a date." id="SpecialistAppointmentDateTime" name="SpecialistAppointmentDateTime" type="text" value="1/1/0001 12:00:00 AM" />
</td></tr>
<tr><td>
<label for="SpecialistAppointmentLocation">SpecialistAppointmentLocation</label>
</td><td>
<input Value="" id="SpecialistAppointmentLocation" name="SpecialistAppointmentLocation" type="text" value="" />
</td></tr>
<tr><td>
<label for="CompletedPathway">CompletedPathway</label>
</td><td>
<input Value="1" id="CompletedPathway" name="CompletedPathway" type="text" value="1" />
</td></tr>
<tr><td>
<label for="CompletedPathwayReason">CompletedPathwayReason</label>
</td><td>
<input Value="" id="CompletedPathwayReason" name="CompletedPathwayReason" type="text" value="" />
</td></tr>
<tr><td>
<label for="Comment">Comment</label>
</td><td>
<textarea Value="" cols="20" id="Comment" name="Comment" rows="2">
</textarea>
</td></tr>
</table>
<p>
<input type="submit" value="Save" class="button" id="btClick"/>
</p>
</form>
我检查了相应字段的 ID,一切似乎都已检查。很神秘。