我不想試圖去喜歡我的客戶端驗證這一輪。也許對於未來的項目,但我只想對我的表單進行一些基本的表單驗證...在asp.net MVC中的jquery驗證4
我知道你可以將這些東西鏈接到你的模型或其他任何東西,但我真的只是想向客戶端顯示一條錯誤消息如果他的輸入不正確。但是,我很難完成任何驗證工作。所以我猜我缺少一些相當簡單的東西。我以爲我的基地都覆蓋了,但顯然不是。
這裏是我納入我的項目,在視圖中的腳本...
<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
}
}
})
形式似乎提交我是否有出生日期... 我缺少什麼?
UPDATE:發佈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>
我檢查相應的字段的標識的,一切似乎退房。非常神祕。
嗯。好眼睛。我不知道爲什麼總是忘記這一點。但它仍然無法以某種方式工作。我查看了調試器,看起來好像我有一個javascript異常。嗯。神祕。 – SoftwareSavant 2012-08-13 12:41:13
你可以發佈你的輸出html - 可能只是一個格式問題?! – bUKaneer 2012-08-13 12:49:13