locked
Looping through ViewData.ModelMetadata.Properties except for null values RRS feed

Answers

  • User-474980206 posted

    the sample is looping thru the meta property data, not the type. it assumed if there is no PropertyName, then its not a matching model model property for binding. the idea of meta properties, is if your model is code generated (old ef models) you should not edit it to add attributes to the properties. so MVC allows a meta attribute and partial classes to add attributes. 

    generally we use POCO objects now and add attributes as needed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 17, 2020 3:11 AM

All replies

  • User711641945 posted

    Hi bank5,

    If you resolve your issue,please post your answer as a new post and mark it as answer.

    Best Regards,

    Rena

    Friday, April 17, 2020 1:22 AM
  • User-474980206 posted

    the sample is looping thru the meta property data, not the type. it assumed if there is no PropertyName, then its not a matching model model property for binding. the idea of meta properties, is if your model is code generated (old ef models) you should not edit it to add attributes to the properties. so MVC allows a meta attribute and partial classes to add attributes. 

    generally we use POCO objects now and add attributes as needed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 17, 2020 3:11 AM