user2107843
user2107843

Reputation: 259

validation summary in mvc 4.0

I am new to mvc I am trying simple validation summary but the validation summary is not showing in UI.IS there any syntax wrong.

   @{Html.ValidationSummary();}
    @{Html.BeginForm();}

    <p>
        Name:[email protected]("Name")
    </p>
    <p>
        Age:[email protected]("Age")
    </p>
    <input type="submit" value="Sign In" />
    <h6>SignIn</h6>
    @{Html.EndForm();}

Upvotes: 0

Views: 2569

Answers (1)

mayabelle
mayabelle

Reputation: 10014

This should work:

@using (Html.BeginForm("YourActionName", "YourControllerName","Upload", FormMethod.Post)) {
    @Html.ValidationSummary(false);
    <p>
        Name: @Html.TextBoxFor(m => m.Name)
    </p>
    <p>
        Age: @Html.TextBoxFor(m => m.Age)
    </p>
    <input type="submit" value="Sign In" />
    <h6>SignIn</h6>
}

...Assuming that you have validation attributes (e.g. [Required]) on the properties on the model.

Notice that the validation summary is inside the Html.BeginForm() block.

Also notice the TextboxFor syntax (rather than Textbox) which makes sure that your properties are strongly typed.

Also, make sure you have these settings in the appsettings section of your web.config file:

<add key="ClientValidationEnabled" value="true"></add>
<add key="UnobtrusiveJavaScriptEnabled" value="true"></add>

Upvotes: 1

Related Questions