我正在按照本指南here创建一个步骤向导来遍历多个页面,每个页面都有表单,同时保存每个表单数据以存储在我的数据库中,但我遇到的问题是在第二页上详细地址'。当我按prevBtn返回上一页'basicDetails'时,我的表单正在尝试进行客户端验证,我得到所有验证错误,而不是发布到我的操作方法,看看是否按下了prevBtn或nextBtn
这是我的地址详细信息页面
<div class="col-sm-7 col-sm-offset-1">
@using (Html.BeginForm("AddressDetails", "User", FormMethod.Post)) {
<div class="row">
<h3>What's the address for this payout method?</h3>
</div>
<div class="row">
<div class="form-group">
<label for="AddressLine1">Street address</label>
@Html.TextBoxFor(m => m.StreetAddressLine1, new { @id = "AddressLine1", @class = "form-control input-lg", placeholder = "e.g. 123 Main St." }) @Html.ValidationMessageFor(m => m.StreetAddressLine1,
"", new { @class = "text-danger" })
</div>
</div>
<div class="row">
<div class="form-group">
<label for="AddressLine2">Apt, suite, bldg. (optional)</label>
@Html.TextBoxFor(m => m.StreetAddressLine2, new { @id = "AddressLine2", @class = "form-control input-lg", placeholder = "e.g. Apt #6" }) @Html.ValidationMessageFor(m => m.StreetAddressLine2,
"", new { @class = "text-danger" })
</div>
</div>
<div class="row">
<div class="col-sm-6" style="padding-left: 0px; padding-right: 5px;">
<div class="form-group">
<label for="City">City</label> @Html.TextBoxFor(m => m.City, new { @id = "City", @class = "form-control input-lg" })
@Html.ValidationMessageFor(m => m.City, "", new { @class = "text-danger" })
</div>
</div>
<div class="col-sm-6" style="padding-left: 5px; padding-right: 0px;">
<div class="form-group">
<label for="State">State / Province</label>
@Html.DropDownListFor(m => m.StateCode, new SelectList(Model.StateList, "Value", "Text"), "", new { @id = "State", @class = "btn-group-lg countryList form-control selectpicker" }) @Html.ValidationMessageFor(m
=> m.StateCode, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label for="PostalCode">Zip code / Postal code</label>
@Html.TextBoxFor(m => m.PostalCode, new { @id = "PostalCode", @class = "form-control input-lg", placeholder = "e.g. 94102" }) @Html.ValidationMessageFor(m => m.PostalCode, "", new { @class =
"text-danger" })
</div>
</div>
<div class="row">
@Html.DropDownListFor(m => m.SelectedCountryId, new SelectList(Model.CountryList, "Value", "Text"), new { @id = "Country", @class = "btn-group-lg countryList form-control selectpicker" })
</div>
<div class="row">
<hr />
</div>
<div class="row">
<div class="col-sm-12">
<input type="submit" name="prevBtn" value='Previous' />
<input type="submit" name="nextBtn" value='Next' />
</div>
</div>
}
</div>
这是我的行动方法
[HttpPost]
public ActionResult AddressDetails(UserAddressViewModel addressViewModel, string prevBtn, string nextBtn)
{
YogaProfileBankAccount obj = GetBankAccount();
if (prevBtn != null)
{
UserBillingViewModel billingViewModel = new UserBillingViewModel();
//bd.CustomerID = obj.CustomerID;
//bd.CompanyName = obj.CompanyName;
return View("BasicDetails", billingViewModel);
}
if (nextBtn != null)
{
if (ModelState.IsValid)
{
//obj.Address = data.Address;
//obj.City = data.City;
//obj.Country = data.Country;
//obj.PostalCode = data.PostalCode;
return View("AccountDetails");
}
}
return View();
}
因此,当我按下之前会发生的情况,所有字段都会尝试验证