user2206329
user2206329

Reputation: 2842

mvc 4 Validation summary appearing before submit

I am creating an application in MVC4. I have a validationsummary on my page as follows,

<div>
            @Html.ValidationSummary()
        </div>

when the page loads, it shows the validation summary and says one of the required fields is required. Why is this shown on load? I thought the validation summary was only shown after a submit?

thanks

<div id="GeneratePaymentContainer" class="content-container">
       <div>
            @Html.ValidationSummary()
        </div>
    <div id="GeneratePaymentPage1">

        <div id="PageHeaderContainer">
            <div id="HelpContainer">
                <h2>@SearchPayment.SearchPlacementsHeader</h2>
                @Html.PageHelp()
            </div>


            @{ Html.RenderPartial("PlacementFilter", Model); }
        </div>
        <div id="BodyContainer">
            <div id="GridActions" class="buttons-container">
                <a id="Print" class="button">@Buttons.PrintButton</a>
            </div>

            @{ Html.RenderPartial("SearchGridResults", Model); }
            <div id="StandardCost"></div>


            <div id="SelectedPlacementContainer"></div>

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

    @using (Html.BeginForm("RequestAction", "Request", FormMethod.Post, new { id = "SundryEntryForm" }))
    {

}...

Upvotes: 0

Views: 1482

Answers (1)

Nilesh Gajare
Nilesh Gajare

Reputation: 6398

try to write your @Html.ValidationSummary() before Html.BeginForm tag

Update : According to this Post Therefore, just create a css rule as follows;

.validation-summary-valid
{
display:none;
}

Upvotes: 1

Related Questions