DisplayName元数据不会显示在视图上

时间:2010-12-16 02:06:23

标签: asp.net-mvc-2 attributes view metadata data-annotations

  

可能重复:
  DisplayName metadata does not show up on view

考虑到以下模型,如何在我的视图中显示正确的DsiplayName。

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

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <% using (Html.BeginForm())
       {%>
    <table>
        <tr>
            <td class="label">
                <%: Html.LabelFor(model => model.User.UserPrimaryEmail)%>
            </td>
            <td class="field">
                <%: Html.TextBoxFor(model => model.User.UserPrimaryEmail)%>
            </td>
            <td class="field-error">
                <div class="field-error-msg">
                    <%: Html.ValidationMessageFor(model => model.User.UserPrimaryEmail)%>
                </div>
            </td>
        </tr>
    </table>
</asp:Content>


public class RegisterViewModel
{
    public User User { get; set; }
}


[MetadataType(typeof(UserMetaData))]
public partial class User : UserBase
{
    //Inherits from Generated Class UserBase
    //to set default values here for the constructor

    // Not used except as a source of metadata
    public class UserMetaData
    {

        [Required]
        [DisplayName("Email Login")]
        [DataType(DataType.EmailAddress)]
        [Email(ErrorMessage = "Invalid Email")]
        public string UserPrimaryEmail { get; set; }


    }

}

表格不显示“电子邮件登录”,但显示“UserPrimaryEmail”

0 个答案:

没有答案