0

In my Model I have a propety decorated with the AdditionalMetadata attribute to pass through help text that I want to render:

[AdditionalMetadata("HelpText", "help text goes here")]

In my EditorTemplate (/views/shared/editorTemplates/Object.ascx) I then check to see if this value is set:

<% if (ViewData.ModelMetadata.AdditionalValues.ContainsKey("HelpText"))
{ %>
  <span class='editor-help'>
    <%= ViewData.ModelMetadata.AdditionalValues["HelpText"].ToString()%>
  </span>
<% } %>

However, when I put a breakpoint on ViewData.ModelMetadata.AdditionalValues, its always empty, even though I'm breaking on the correct field and the attribute is definitely set. I'm using MVC4 in case the behaviour has changed since MVC3?

Is there any other step I have to do to pass a custom vale through from the model to the view?

Thanks

tereško
  • 58,060
  • 25
  • 98
  • 150
LDJ
  • 6,896
  • 9
  • 52
  • 87

1 Answers1

0

Managed to solve this in the end. Ultimately I had to call

prop.AdditionalValues["HelpText"])

where prop is of type ModelMetadata, while enumurating the collection:

<% foreach(var prop in ViewData.ModelMetadata.Properties.Where(md => md.ShowForEdit && !ViewData.TemplateInfo.Visited(md))){ %>

Not sure why they aren't showing on the ViewData.ModelMetadata object though.

LDJ
  • 6,896
  • 9
  • 52
  • 87