开发者

MVC 3: How can I validate partial views on a page and issue one Post?

I'm adding 2 partial views, each with its own Form into a container view. The partial views have their own cotrollers. The container view has its own Form, too, but I'm not nesting Forms.

@Html.Action("Create", "RequestorInformation")
@Html.Action("Create", "UserInformation")

The Form for the RequestorInformation partial view looks like this:

@using (Html.BeginForm("Create", "RequestorInformation", new { id = "formRequestorInformation" })) { 
@Html.ValidationSummary(true)

The Form for the UserInformation partial view looks like this:

@using (Html.BeginForm("Create", "UserInformation", new { id = "formUserInformation" })) { 
@Html.ValidationSummary(true)

The Form for the container view looks like this:

@using (Html.BeginForm("Create", "SSAR", new { id = "formSSAR" })) {

To validate and save all the data on the page I run this script A (thanks to Milimetric ):

    $('form').each(function (formIndex, formElement) {
        var f = $(formElement);
        alert('formIndex: ' + formIndex);
        if ($(this).validate()) {
            $.post(f.attr('action'), f.serialize(), successfulFormPost)
        }
    });

The script recurses through each Form, which if valid, Posts to the appropriate method on a controller. The Posts for the partial开发者_开发问答 views are executed and ModelState is evaluated, but there are no data operations.

My issue is this: I need to 'manually' validate each partial view and then make one Post for the container Form that will perform data operations as needed.

I've tried to do the following with this script B:

$("#SubmitForm").click(function (event) {
    event.preventDefault();
    $('formRequestorInformation').validate();
    if ($('formRequestorInformation').valid()) {
        alert('Requestor Form Is Valid!!');
    }
});

But I get the following error in jQuery Validation Plugin 1.8.0.:

Microsoft JScript runtime error: 'this.0.form' is null or not an object

Question: How can I individually validate the partial views on the page and when all are valid, make one Post?

Thanks,

Arnold


I'm fairly certain that the libraries I was using were not in sync. I started over from scratch after reinstalling and repairing and now things work as advertised.

I'm using user controls w/o forms added into a main Form like this:

@Html.Action("Action", "Controller")

A simple submit button validates the whole Form

Repaired Telerik: Telerik_Extensions_for_ASPNET_MVC_2011_1_315_OpenSource

Thanks,

Arnold

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜