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)

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

I know about the localization but the problem here is that I must use EditorForModel to get the proper name from displayattribute och displaynameattribute
have you tried setting the resourcetype that is missin in your model? what happend? with only displayattribute?
I have tried with resourcetype and with dislayname attribute but none of this works, it still uses the property name for label text
try looking at this article about ModelMetadataProviders dotnetcurry.com/ShowArticle.aspx?ID=715

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.