0

我在这样的 mvc 项目的一个视图上有 3 个表单”

看法:

 <div>
        <fieldset>            
            <legend>Deposit Money</legend>
            <div>@Html.LabelFor(u=>u.AccountNumber1)</div>
            <div>@Html.DropDownList("Accounts",  "-- Select Account --")
            </div>

            <div>@Html.LabelFor(u=>u.Amount)</div>
            <div>@Html.TextBoxFor(u => u.Amount,new {style = "width:150px"})
                @Html.ValidationMessageFor(u => u.Amount)
            </div>

            <div>@Html.LabelFor(u=>u.Comment)</div>
            <div>@Html.TextAreaFor(u => u.Comment,new {style = "width:250px"})
                @Html.ValidationMessageFor(u => u.Comment)
            </div>

            <input type="submit" value ="Submit" />
            <input type="reset" value ="Clear" />

        </fieldset>

    </div>

}
</div> 
<div id="middlepanel" style="position:absolute;left:33%;right:33%;">
    @using (Html.BeginForm("Withdrawal", "ATM", FormMethod.Post, new { })) 
{
    @Html.ValidationSummary(true,"Deposit Failed. Check Your Details");

    <div>
        <fieldset>
            <legend>Withdraw Money</legend>
            <div>@Html.LabelFor(u=>u.AccountNumber1)</div>
            <div>@Html.DropDownList("Accounts",  "-- Select Account --")
            </div>

            <div>@Html.LabelFor(u=>u.Amount)</div>
            <div>@Html.TextBoxFor(u => u.Amount,new {style = "width:150px"})
                @Html.ValidationMessageFor(u => u.Amount)
            </div>

            <div>@Html.LabelFor(u=>u.Comment)</div>
            <div>@Html.TextAreaFor(u => u.Comment,new {style = "width:250px"})
                @Html.ValidationMessageFor(u => u.Comment)
            </div>

            <input type="submit" value ="Submit" />
            <input type="reset" value ="Clear" />

        </fieldset>

    </div>

}
</div> 
<div id="rightpanel" style="position:absolute;right:0;width:33%;">
    @using (Html.BeginForm("Transfer", "ATM", FormMethod.Post, new { })) 
{
    @Html.ValidationSummary(true,"Deposit Failed. Check Your Details");

    <div>
        <fieldset>
            <legend>Transfer Money</legend>
            <div>@Html.LabelFor(u=>u.AccountNumber1)</div>
            <div>@Html.DropDownList("Accounts",  "-- Select Account --")
            </div>
            <div>@Html.LabelFor(u=>u.AccountNumber2)</div>
            <div>@Html.DropDownList("Accounts",  "-- Select Account --")
            </div>

            <div>@Html.LabelFor(u=>u.Amount)</div>
            <div>@Html.TextBoxFor(u => u.Amount,new {style = "width:150px"})
                @Html.ValidationMessageFor(u => u.Amount)
            </div>

            <div>@Html.LabelFor(u=>u.Comment)</div>
            <div>@Html.TextAreaFor(u => u.Comment,new {style = "width:250px"})
                @Html.ValidationMessageFor(u => u.Comment)
            </div>

            <input type="submit" value ="Submit" />
            <input type="reset" value ="Clear" />

        </fieldset>

    </div>

}
</div>

在我的控制器中,我正在处理上述每个功能。

但是,当其中一个表单出现错误(即空白字段​​)时,所有表单上都会显示错误(validationSummary)

我怎样才能建立每个表格的个别错误?

4

1 回答 1

0

考虑为每个表单使用局部视图,并在主视图中调用局部视图

@Html.Partial("PartialViewName")
于 2013-09-27T11:21:00.117 回答