添加ModelError MVC Web api 5后,CSS无法正确加载

时间:2018-04-04 09:24:36

标签: asp.net-web-api asp.net-mvc-5

我们正在使用捆绑,并且在添加ModelError MVC Web api 5后CSS未正确加载 这是我们在web api控制器中的代码:

                    string errorMessage = (string)TempData["errorMsg"];
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    ModelState.AddModelError("AccountNumber", errorMessage);
                }

实际上,当我们在post action方法中发布数据时,如果我们在请求中出现任何错误,我们会从post重定向到get action方法。

这是我的HTML:

<div id="collapseTwo" class="collapse show" role="tabpanel" aria-labelledby="headingTwo">
    <div class="card-block">

        <div class="bank_account">
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="row">

                <div class="col-xl-4 col-lg-12 col-md-4 col-12">
                    <label>Account Holder Name</label>
                </div>

                <div class="col-xl-8 col-lg-12 col-md-8 col-12">
                    <div class="form-group">
                        @Html.TextBoxFor(model => model.BankAccount.AccountHolderName, new { @class = "form-control", placeholder = "Account Holder Name" })
                        @Html.ValidationMessageFor(model => model.BankAccount.AccountHolderName, "", new { @class = "text-danger holder_name" })
                    </div>
                </div>

            </div>

            <div class="row">
                @Html.EditorFor(model => model.BankAccount)
            </div>

            <div class="row">

                <div class="col-xl-4 col-lg-12 col-md-4 col-12">&nbsp;</div>
                <div class="col-xl-8 col-lg-12 col-md-8 col-12">
                    <div class="form-group">
                        <label>
                            @Html.CheckBoxFor(model => model.AgreeWithTermCondtion, new { @class = "term_height" }) I agree with <a class="tmc" id="anch_terms_and_conditions" href="javascript:void(0)">Terms &amp; Conditions </a>
                        </label>
                        @Html.ValidationMessageFor(model => model.AgreeWithTermCondtion, "", new { @class = "text-danger" })
                    </div>
                </div>

            </div>

            <div class="row mt-2">

                <div class="col-xl-4 col-lg-12 col-md-4 col-12">&nbsp;</div>
                <div class="col-xl-8 col-lg-12 col-md-8 col-12">
                    <button type="submit" class="btn btn_pay" id="btn_create_dd_plan"> Create Plan </button>

                    @CancellationButtion()
                </div>

            </div>

        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

将html替换为下面的一个:

<div id="collapseTwo" class="collapse show" role="tabpanel" aria-labelledby="headingTwo">
    <div class="card-block">
 @Html.ValidationSummary(true, "", new { @class = "text-danger" })

        <div class="bank_account">
            <div class="row">

                <div class="col-xl-4 col-lg-12 col-md-4 col-12">
                    <label>Account Holder Name</label>
                </div>

                <div class="col-xl-8 col-lg-12 col-md-8 col-12">
                    <div class="form-group">
                        @Html.TextBoxFor(model => model.BankAccount.AccountHolderName, new { @class = "form-control", placeholder = "Account Holder Name" })
                        @Html.ValidationMessageFor(model => model.BankAccount.AccountHolderName, "", new { @class = "text-danger holder_name" })
                    </div>
                </div>

            </div>

            <div class="row">
                @Html.EditorFor(model => model.BankAccount)
            </div>

            <div class="row">

                <div class="col-xl-4 col-lg-12 col-md-4 col-12">&nbsp;</div>
                <div class="col-xl-8 col-lg-12 col-md-8 col-12">
                    <div class="form-group">
                        <label>
                            @Html.CheckBoxFor(model => model.AgreeWithTermCondtion, new { @class = "term_height" }) I agree with <a class="tmc" id="anch_terms_and_conditions" href="javascript:void(0)">Terms &amp; Conditions </a>
                        </label>
                        @Html.ValidationMessageFor(model => model.AgreeWithTermCondtion, "", new { @class = "text-danger" })
                    </div>
                </div>

            </div>

            <div class="row mt-2">

                <div class="col-xl-4 col-lg-12 col-md-4 col-12">&nbsp;</div>
                <div class="col-xl-8 col-lg-12 col-md-8 col-12">
                    <button type="submit" class="btn btn_pay" id="btn_create_dd_plan"> Create Plan </button>

                    @CancellationButtion()
                </div>

            </div>

        </div>
    </div>
</div>