ModelMetaData, Custom Class Attributes and an indescribable question

前端 未结 2 882
长情又很酷
长情又很酷 2021-02-09 20:13

What I want to do seems so simple.

In my index.cshtml I want to display the WizardStepAttribute Value

So, a user will see at the top of each page,

2条回答
  •  情书的邮戳
    2021-02-09 20:42

    In our case we just needed an attribute that implements the IMetadataAware interface:

    https://msdn.microsoft.com/en-us/library/system.web.mvc.imetadataaware(v=vs.118).aspx

    In your case, this could be:

    public class WizardStepAttribute : Attribute, IMetadataAware
    {
        public string Name;
    
        public void OnMetadataCreated(ModelMetadata metadata)
        {
            if (!metadata.AdditionalValues.ContainsKey("WizardStep"))
            {
                metadata.AdditionalValues.Add("WizardStep", Name);
            }
        }
    }
    

提交回复
热议问题