1

I have a model like this

[MetadataType(typeof(PageMetadataMetadata))]
public class PageMetadata : IPageMetadata {
    public virtual string Name { get; set; }
}

and my metadata class like this

internal class PageMetadataMetadata {
    [Display(Name = "Title", Order = 10, Prompt = "My awesome page")]
    [Required(ErrorMessage = "Name_Required")]
    public virtual string Name { get; set; }
}

When I use this model in my view I cannot get it to use the name from my DisplayAttribute?

@Html.LabelFor(model => model.CurrentModel.Metadata.Name)
marcus
  • 9,616
  • 9
  • 58
  • 108

1 Answers1

1

With DisplayAttribute, you have to set also the ResourceType. If you don't want to use localization try using DisplayNameAttribute.

Iridio
  • 9,213
  • 4
  • 49
  • 71
  • I know about the localization but the problem here is that I must use EditorForModel to get the proper name from displayattribute och displaynameattribute – marcus Sep 18 '11 at 09:45
  • have you tried setting the resourcetype that is missin in your model? what happend? with only displayattribute? – Iridio Sep 18 '11 at 09:58
  • I have tried with resourcetype and with dislayname attribute but none of this works, it still uses the property name for label text – marcus Sep 18 '11 at 11:46
  • try looking at this article about ModelMetadataProviders http://www.dotnetcurry.com/ShowArticle.aspx?ID=715 – Iridio Sep 18 '11 at 13:36