小编Jua*_*rin的帖子

asp net mvc局部视图验证

你好你好吗?我正在尝试验证ASP NET MVC中的表单.

我有部分视图"地址",我重用于某些实体,如公司,人员等.

我的问题是,当我提交表单时,只有父视图的控件才会被验证,而局部视图中的控件则不会.

这里有一些代码我希望你可以帮助我

人物观点

@model Entities.Person


@using (Html.BeginForm("Create", "Person", FormMethod.Post))
{

    <table>
        <tr>
            <td>
                @Html.LabelFor(model => model.FirstName)
                <div class="control">
                    @Html.TextBoxFor(model => model.FirstName, new { @maxlength = 7, @class = "numeric"})
                    @Html.ValidationMessageFor(model => model.FirstName)
                </div>
                <div class="spacer-short"></div>
            </td>
            <td>
                @Html.LabelFor(model => model.LastName)
                <div class="control">
                    @Html.TextBoxFor(model => model.LastName, new { @maxlength = 7, @class = "numeric"})
                    @Html.ValidationMessageFor(model => model.LastName)
                </div>
                <div class="spacer-short"></div>
            </td>
        </tr>
    </table>
    @{ Html.RenderAction("Index", "Address", new {id = Model.AddressId});} //Renders the Address form part

    <div class="spacer"></div> …
Run Code Online (Sandbox Code Playgroud)

validation asp.net-mvc partial-views

0
推荐指数
1
解决办法
4919
查看次数

标签 统计

asp.net-mvc ×1

partial-views ×1

validation ×1