If you resolve your issue,please post your answer as a new post and mark it as answer.
Best Regards,
Rena
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
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.
Member
116 Points
350 Posts
Looping through ViewData.ModelMetadata.Properties except for null values
Apr 16, 2020 07:55 PM|bank5|LINK
I found this thread which I thought was pretty neat - https://forums.asp.net/t/1716207.aspx?ViewData+ModelMetadata+Properties+to+display+all+fields+in+a+model+exclude+null+values
I wasn't sure about the solution though as
Will always return true. What is suppose to be checked in the if statement to get the value of the property?
(I tried responding directly to the other thread but it's locked.)
EDIT: I wound up using this which is working as intended:
Contributor
2690 Points
874 Posts
Re: Looping through ViewData.ModelMetadata.Properties except for null values
Apr 17, 2020 01:22 AM|Rena Ni|LINK
Hi bank5,
If you resolve your issue,please post your answer as a new post and mark it as answer.
Best Regards,
Rena
All-Star
58234 Points
15673 Posts
Re: Looping through ViewData.ModelMetadata.Properties except for null values
Apr 17, 2020 03:11 AM|bruce (sqlwork.com)|LINK
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.