部分视图提交中的客户端验证

时间:2016-08-05 04:02:43

标签: asp.net-mvc validation asp.net-mvc-partialview

当部分视图直接加载到_Layout时,我在客户端验证中没有问题,并按字段错误显示字段,但是当调用部分视图与索引页的一部分相同时:

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

任何人都可以帮我理解这个问题吗? TNX。

1 个答案:

答案 0 :(得分:0)

您可能会被Html.BeginForm打电话,表格中的表格不正确,请检查