0

i am trying to validate a form in a JQuery model dialog that is dynamically loading a view generated from a jquery ajax call

there is already one form on the page and this form is being created under the other form, and everything seems to be orking but I am not sure if its possible to use the regular MVC validation on this second form since its being dynamicly created.

here is the HTML view for the main

 <% Html.EnableClientValidation(); %> <% using (Html.BeginForm("UpdateFund", "AdministerFundFeature", FormMethod.Post, new { enctype = "multipart/form-data" })) { %> <fieldset> ... <input type="submit" value="Submit" /> </fieldset> <%} %> <div id="GrantRecipDialog" title="Add/Edit Grant Recipiant"> <div id="GrantRecipContent"></div> </div> 

on a button click this function is fired populationg the div with the new form

var url = "<%: Url.Action( "AddOrUpdateGrantRecip", "AdministerFundFeature") %>" + "?aGrantId=" + aGrantId + "&aFundId=" + aFundId; $.ajax({ url: url, success: function (data) { $('#GrantRecipContent').html(data); /*place the data here, and rerender the section*/ $('#GrantRecipDialog').dialog("open"); }, error: function () { alert("There was a problem with your request, please resubmit your request."); },//?? complete: function() {} }); } 

and here is the view that gets rendered in the pop up

<% Html.EnableClientValidation(); %> <% using (Ajax.BeginForm("updateGrant", "AdministerFundFeature", new AjaxOptions { OnComplete="function(){onGrantRecipUpdate()}", OnFailure="function(){return onGrantFail()}"}, new { @id = "frmID" })) { %> <fieldset> ... </fieldset> <%}%> 

is it possible to hook the MVC validation up for the pop up, it works fine in the first form, but I am not sure how to explicitly tell MVC to cerate the validation information for the new for generated

    2 Answers 2

    1

    Use this after create the form:

    $.validator.unobtrusive.parse($('form')); 
      0

      I came up against this a while ago, and found that I just had to feed my validation errors into a JSON result and deal with them using the complete method of the Ajax form.

      I couldn't find the article I linked to, but did find this;

      http://www.hightech.ir/SeeSharp/aspnet-validation-with-ajax-and-json

      1
      • One other thing to know about, if your forms share common field names (i.e two models that have address, displaying two forms with those model bound fields in), that's going to confuse things a little. So, you need to attach a prefix to one of the models to distinguish it from the other.CommentedApr 26, 2011 at 0:49

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.