我有一个根视图,其中有两个部分视图,基于按钮点击加载到div中:
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Donation information</legend>
<p>
@Html.LabelFor(m => m.DonationType.DonationTypex) <br />
@Html.DropDownListFor(model => model.DonationType.DonationTypeID, ViewBag.DonationTypes as
SelectList, htmlAttributes: new { @id = "selectList" })
@Html.ActionLink("Select", "ContinueDonation", "Donation", htmlAttributes: new { @id =
"btnSelect1" })
</p>
<div id="donationSection1"></div>
<br />
<input id="btnAddPayment1" type="button" value="Add Payment Info" />
<br /><br />
<div id="paymentSection1"></div>
<input type="submit" id="btnSubmitDonation" value="Save" />
<input type="button" id="btnCancelDonation" value="Cancel" />
</fieldset>
}
加载到donationSection1和paymentSection1 div的部分视图共享相同的模型,只包含其中不同属性的编辑器,标签等...只是想知道如何让它来验证部分视图...如果提交/保存按钮位于根视图...
...加载div的jquery ...(控制器返回共享同一模型的部分视图):
$("#btnSelect1").click(function () {
var donationTypeID = $(this).closest('p').find('#selectList').val();
var id = parseInt(donationTypeID);
var route = '/Donation/ContinueDonation?dTypeId=' + id;
$("#donationSection1").load(route, function () {
$("#donationSection1").show('slow');
});
return false;
});
答案 0 :(得分:1)
尝试使用jquery validator.unobtrusive.parse
$("#btnSelect1").click(function () {
var donationTypeID = $(this).closest('p').find('#selectList').val();
var id = parseInt(donationTypeID);
var route = '/Donation/ContinueDonation?dTypeId=' + id;
$("#donationSection1").load(route, function () {
$("#donationSection1").show('slow');
});
jQuery.validator.unobtrusive.parse('#donationSection1')
return false;
});
这里是更多解释的链接
http://itmeze.com/2010/10/08/client-side-validation-after-ajax-partial-view-result-in-asp-net-mvc-3/