Html.ValidationSummary in asp.net mvc 3

Instead of always displaying all validation errors, the Html.ValidationSummary helper method has a new

option to display only model-level errors. This enables model-level errors to be displayed in the
validation summary and field-specific errors to be displayed next to each field.

<%@ Page Title="" Language="C#" MasterPageFile="/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.Product>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<title>Create</title>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Create</h2>

    <@= Html.ValidationSummary() @>

    <@ using (Html.BeginForm()) {>

        <fieldset>
            <legend>Fields</legend>
            <p>
                <label for="Name">Name:</label>
                <@ Html.TextBox("Name") %>
                <@ Html.ValidationMessage("Name", "*") >
            </p>
 </p>
        </fieldset>

    @ } 
    <div>
        <@Html.ActionLink("Back to List", "Index") >
    </div>

</asp:Content>

Ebook Download
View all
Learn
View all