0

I have a Dictionary<int, PostCode> called PostcodeData in an MVC4 VM. I'm trying to bind to the Serialized property on the PostCode DTO. In Razor, I've tried:

@Html.HiddenFor(m => m.PostcodeData [code.Id].Serialized)

And

<input type="hidden" name="PostcodeData[@code.Id].Serialized"  />

But the dictionary is empty when the page posts back. According to ASP.NET MVC Binding to a dictionary I should be able to bind to it though. Am I missing something?

Echilon
  • 10,064
  • 33
  • 131
  • 217
  • What HTML did `` generate? _Use View Source in the browser._ – mjwills Jun 13 '18 at 13:34
  • That is not possible - refer [this answer](https://stackoverflow.com/questions/41258733/bind-dictionary-with-list-in-viewmodel-to-checkboxes/41560929#41560929) for how you would need to bind to a `Dictionary`. But since you are not editing it, the why are you trying to send to back again unchanged? –  Jun 13 '18 at 13:38
  • I'm modifying it with JavaScript, the value stored represents a value in a series of checkboxes. – Echilon Jun 13 '18 at 13:48
  • Thanks @StephenMuecke - I've experimented a range of fields from that post but nothing is working. Having a list isn't really feasible. – Echilon Jun 13 '18 at 14:09
  • Did you read the link? (you would need to create an input for each property of `PostCode` plus the key) –  Jun 13 '18 at 14:11

0 Answers0