我正在尝试使用HTML.ListboxFor()控件在页面上使用验证。我在我的页面上有几个HTML.DropDownListFor()控件按照设计进行验证,但是当我在列表框中选择一个项目时,页面会在控制器上触发HttpPost Action Method,绕过form.submit()函数会解雇我的验证。
如果需要任何其他信息来解决此问题,请与我们联系。
我的HTML如下......
//....more HTML
<div class="span6">
@Html.LabelFor(m => m.RaceAsList)
<div class="controls">
@Html.ListBoxFor(m => m.RaceAsList, Race.SelectRace, Html.GetI18LHtmlAttributesFor(m => m.Race, new { @class = "span4 subtext upper defaultIsZero hasPatientDeclines", tabindex = 13 }))
@Html.ValidationMessageFor(m => m.RaceAsList)
<br />
<span class="muted">@(Html.Raw(Kiosk.ResourceFiles.Resource.RaceHelp))</span>
</div>
</div>
<div class="span6">
@Html.LabelFor(m => m.Ethnicities)
<div class="controls">
@Html.DropDownListFor(m => m.Ethnicities, Ethnicities.SelectEthnicities, Html.GetI18LHtmlAttributesFor(m => m.Ethnicities, new { @class = "span4 upper defaultIsZero hasPatientDeclines", tabindex = 14 }))
@Html.ValidationMessageFor(m => m.Ethnicities)
</div>
</div>
//....more HTML
我的.js如下:
//...more javascript
$("form").submit(function() {
if (preSubmit != undefined && $.isFunction(preSubmit)) {
preSubmit();
}
if (!isForeignAddress) {
$(".phone").each(function() {
nums = pv.stripAlphaChars($(this).val());
$(this).val(nums);
});
}
if ($(".requireOptOut").size() > 0) {
requireOptOut($(".requireOptOut:first"));
}
return true;
});
//...more javascript
我的控制器如下:
//...more C#
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult PatientInfo(KioskPatientEntity model, FormCollection form)
{
LoadFromSession();
var kioskPatient = PatientManagerService.GetPatientBySession(NavigationSession.SessionPk, Environment, KioskPatientChildPrefetch.None);
if (kioskPatient != null)
{
kioskPatient.MergeChanges(model);
}
else
{
kioskPatient = model;
kioskPatient.SessionPk = NavigationSession.SessionPk;
}
var properties = new []
{
KioskPatientFieldIndex.FirstName.ToString()
,KioskPatientFieldIndex.MiddleName.ToString()
,KioskPatientFieldIndex.LastName.ToString()
,KioskPatientFieldIndex.Gender.ToString()
,KioskPatientFieldIndex.Ssn.ToString()
,KioskPatientFieldIndex.SsnOptedOut.ToString()
,KioskPatientFieldIndex.BirthDate.ToString()
,KioskPatientFieldIndex.Address1.ToString()
,KioskPatientFieldIndex.Address2.ToString()
,KioskPatientFieldIndex.Zip.ToString()
,KioskPatientFieldIndex.City.ToString()
,KioskPatientFieldIndex.State.ToString()
,KioskPatientFieldIndex.Country.ToString()
,KioskPatientFieldIndex.Race.ToString()
,KioskPatientFieldIndex.Ethnicities.ToString()
,KioskPatientFieldIndex.PreferredLanguage.ToString()
,KioskPatientFieldIndex.HearFrom.ToString()
,KioskPatientFieldIndex.Practice.ToString()
,KioskPatientFieldIndex.AlternateLocation.ToString()
};
kioskPatient.InitializeRaceList(ListManagerService.GetRaceList());
//var List = kioskPatient.RaceAsList;
//var raceComingtrhough = kioskPatient.Race;
//var nameComing = kioskPatient.FirstName;
return SaveKioskPatientEntity(kioskPatient, properties,
new SequenceButtonTypes[] {SequenceButtonTypes.NextButton});
}
//...more C#