0

我有一个根视图,其中包含两个部分视图,它们基于单击按钮加载到 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" })
        &nbsp;&nbsp;
        @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;
    });
4

1 回答 1

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/

于 2012-05-03T04:33:11.520 回答