ViewModel object type properties in a collection are null on POST
I have a View that renders inputs for custom field types. These are dynamic and configured by admins, each custom field can be an int
, DateTime
, bool
, etc. Because of this I store CustomField
values as object
and back them by a sql_variant
column type in SQL Server. The ViewModel for this View contains a collection of CustomFields
:
These are rendered in my View using a for loop:
These do get posted back to the controller action:
But the Value
property of each CustomField
is null, all other properties are populated correctly.
Edit: It appears to indeed be caused by binding to a property of type object
. If I change the Value
property in CustomFieldViewModel
to string
the property is set correctly in the controller action on Post.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.