Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display name in Data Entity framework

I'd like to know how to change the display name of a model, and customize error messages in Entity Framework. I tried the following but it didn't work.

    [Required(ErrorMessage = "Required .... :")]
    [Display(Name = "Name Agency : ")]
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.String Nag
    {
        get
        {
            //code
        }
        set
        {
           //code
        }
    }

This is the code behind my form that adds data into my database. I've omitted irrelevant lines.

 <% using (Html.BeginForm("addcar", "Agence", FormMethod.Post, new { @class = "search_form" }))
   { %>
    <%: Html.ValidationSummary(true) %>
        <div class="editor-label">
            <%: Html.LabelFor(model => model.Dmcv) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.Dmcv) %>
            <%: Html.ValidationMessageFor(model => model.Dmcv) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.Puisv) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.Puisv) %>
            <%: Html.ValidationMessageFor(model => model.Puisv) %>
        </div>

        // Similaire code

        <p>
            <input type="submit" value="Create" />
        </p>
<% } %>
like image 527
Chlebta Avatar asked Dec 17 '22 01:12

Chlebta


1 Answers

Change [Display(Name = "Name Agency")] to [DisplayName("Name Agency")] instead.

like image 178
cubski Avatar answered Dec 30 '22 16:12

cubski