开发者

MVC 3.0 newbie - how do I set display name?

Consider this class used for DB mapping.

[Bind()]
public class ActiveType
{

    [Key()]
    public int ID { get; set; }

    [Display(Name = "Navn")]
    public string Name
    {
        get;
        set;
    }

    public string Prefix { get; set; }
    public开发者_开发百科 string Suffix { get; set; }

}

As you can see, I tried to use the Display annotation to make MVC use that name when it auto-generates entity-framework CRUD pages. However, it ignores it. How do I change this? Is it possible through annotations?


If you are genarating your domain classes it will remove the attributes you have added. It seems like you are using the domain object in entity framework layer for the model in MVC layer. This is not a good practice. You need to create separate view models (http://blogs.msdn.com/b/simonince/archive/2010/01/26/view-models-in-asp-net-mvc.aspx) for the MVC layer. Because you need to separate the presentation logic from the data layer. You can use something like AutoMapper to map domain object to view model. http://sourceforge.net/projects/automapper-dn/


The example I provided actually worked, but not for auto-generated EF pages, where it would ignore it in some cases.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜