Validation not working on partial views

I have a root view with two partial views that get loaded into divs based on a button click. Here's the gist of the root view:

@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>
}

The partial views that are loaded into the donationSection1 and paymentSection1 divs share the same Model, just contain editors, labels etc for different properties within it... just wondering how I can get it to validate the partial views... if the submit/save button is on the root view... thanks!

...jquery that loads div... (controller returns partial view sharing same model):

  $("#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;
    });

I guess my next question would be how to best go about posting back the data all at once to the controller...

Answers


try using 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;
    });

here is the link with more explanations

http://itmeze.com/2010/10/08/client-side-validation-after-ajax-partial-view-result-in-asp-net-mvc-3/


Need Your Help

Collating timestamped events into date ranges with pandas

python datetime pandas

I have a master data frame with batch numbers and a datetime range for which these batches occured like so:

bulk insert csv from rhel 5 to sql server

sql-server linux csv

I have to import a CSV from a redhat linux server into the SQL Server. I am using the bulk insert command. Below is the query I am using:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.