0

When Partial View load in _Layout directly, I have no Problem in Client Validation and shows field by filed error, But When call Partial View as same as one part of index page:

@Html.Partial("_CreateUser", Model)

_CreateUser PartialView:

    @model ProjInMvc.Models.User

<div id="update_panel"></div>

    @using (Ajax.BeginForm("CreateUser", "Home",null, new AjaxOptions { UpdateTargetId = "update_panel", Url = "/Home/CreateUser", HttpMethod = "Post",InsertionMode =InsertionMode.Replace }, new { @class = "pull-right" }))
    {
    @Html.AntiForgeryToken()
    <div class="form-horizontal">
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })

    <div class="form-group">
        @Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.UserName, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.UserName, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Create" class="btn btn-default")" />
        </div>
    </div>
    </div>
}

Can anyone help me to understand this problem? Tnx.

aas
  • 11
  • 2
  • 1
    It makes no difference if its in a layout or the main view. Are you loading the partial dynamically after the page has been rendered (i.e. using ajax)? –  Aug 05 '16 at 04:04
  • Yes, _CreateUser partial view is Ajax form. – aas Aug 05 '16 at 12:03
  • No, I mean is the form being loaded dynamically. If so, you need to reparse the $.validator –  Aug 05 '16 at 12:06
  • Please guide me how can i use "$.validator" in partial view?! – aas Aug 05 '16 at 13:32
  • Refer [this answer](http://stackoverflow.com/questions/31768946/required-field-validations-not-working-in-jquery-popup-mvc-4/31769058#31769058) –  Aug 05 '16 at 21:15

1 Answers1

0

You may be call in Html.BeginForm, form in form is incorrect, please check that

shady youssery
  • 430
  • 2
  • 17