0

in the MVC i show partial view with jquery Dialog :

    @Html.Raw(@Ajax.ActionLink("replaceText", "AddToMembers", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "result", InsertionMode = InsertionMode.Replace, OnSuccess = "openPopup" }).ToString().Replace("replaceText" , "<img src='images/btn_12.jpg' width='205' height='72' border='0'>"))

(AddToMemer return partial View)

my member model class is like this :

       public class Members
        {
            public int id { get; set; }
            [Required(ErrorMessage=" *",AllowEmptyStrings=false)]

            public string name { get; set; }
            [Required(ErrorMessage = "*", AllowEmptyStrings = false)]
            [RegularExpression(@"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$", ErrorMessage = "*")]

            public string email { get; set; }


            public bool isValid { get; set; }

            public DateTime date { get; set; }

        }

and this is my partial view : (csFile)

@model MVC.Models.Members
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")"type="text/javascript"> </script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"type="text/javascript"></script>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(false)
    <fieldset>
        <legend >register</legend>
        <div style="font-family: Tahoma; font-size: 12px;">
        <div class="editor-label">
            @Html.LabelFor(model => model.name)
              <br />
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.name)
            <br />
            @Html.ValidationMessageFor(model => model.name)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.email)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.email)
              <br />
            @Html.ValidationMessageFor(model => model.email)
        </div>

        <p align=center>
            <input id="SubmitButton" type="submit" class="normalText" value="send" />
        </p>
        </div>
    </fieldset>


}

but when dialog is load and i click on the send button ,validation does not checked at client side and i redirected to new page and validation is checked there . what's the problem ?

tereško
  • 58,060
  • 25
  • 98
  • 150
MHF
  • 511
  • 8
  • 22
  • possible duplicate of [MVC3 Unobtrusive Validation Not Working after Ajax Call](http://stackoverflow.com/questions/7048726/mvc3-unobtrusive-validation-not-working-after-ajax-call) – jgauffin Apr 03 '12 at 12:48

1 Answers1

0

I'm prsumiong that because you've tagged this MVC3 you want to use unobtrusive javascript validation, in which case you need to follow the steps here:

http://davidhayden.com/blog/dave/archive/2010/12/30/UnobtrusiveJavaScriptASPNETMVC3AjaxHelpers.aspx

Liam
  • 27,717
  • 28
  • 128
  • 190