views:

415

answers:

2

Hey all, I'm facing a really strange problem that has me smoked.

I have a fairly simple scenario where I have a strongly typed view that is correctly populated from the controller on the GET, but then when it POSTS the form to the controller, the Reqeust is full of all the right values and right key names for the default model binder to correctly populate one of my model objects, and the DMB creates the correct opject, but it never populates any of the properties, they're all in their default state.

This was working before, the only changes I can think of were that I tried a custom modelbinder (then removed it; double checked to make sure I'm not still using that), and I refactored the model to have a base class with some of the props.

Any thoughts?

A: 

Got it. The model had been refactored in a way which naturally affected the ability of the mdoel binder to populate it.

Paul
How did you refactor it and what did you do to make it work? I can't tell if my problem is similar to yours.
Tilendor
sorry for being mysterious. Basically, I had been pushing a Person object to the view in the GET action and then getting a Person object from the form in the POST action. I changed the GET action to populate the form w/ a viewmodel that had more information, and the viewmodel had a Person as one of its properties, which changed how the names were generated in the form fields. Changing the POST to use a more similar structure fixed the problem.
Paul
I've got a similar problem - what do you mean 'changing the post'?
codeulike
I meant the names of the form fields.
Paul
A: 

Could you give more details? I'm facing the same problem with the default model binder.

Marc
sure. In my case I hadn't changed the post-side action, but on the get-side action I had refactored to use a view model. The viewmodel had one property that was a Person, but when the form was generated by the view scaffolding it gave it names that the modelbinder couldn't figure out were supposed to map the same on the way in.
Paul