I have a structure with a parent VDO with a collection of child VDO and the child VDO consists of collection of other VDO.
the structure is as below
Public Class AVDO
{
public string name {get ;set;}
public IList<BVDO> bcollection { get ; set ;}
}
Public Class BVDO
{
public xyz {get ; set;};
public IList<CVDO> {get ; set;};
}
I am binding AVDO to my view and I could get the values displayed on my view. But when I do a submit : postback.. I get the object bcollection as null.
Please note: I have done the binding of the objects in the respective VOD's.
Able to get the values for name in AVDO but not for bcollection.
Can anyone let me know what have gone wrong here or is there any solution for it.
Default model binder is able to read back everything if the right name convention is used in your input fields, and if you don't need to perform delete and insert of list items and all fields are displayed in input fields without "holes", that is without
items in the collection that are for instance rendered in display mode and not in input fields.
If you are in the condition above you need only to take kare of using right names, if not, the problem becomes quite difficult and you might consider using some DataGrid that do all the job for you.
sudhir_waghc...
0 Points
1 Post
Getting VDO null on postback on submit button in MVC controller
Feb 03, 2011 12:15 PM|LINK
Hi,
I have a structure with a parent VDO with a collection of child VDO and the child VDO consists of collection of other VDO.
the structure is as below
Public Class AVDO
{
public string name {get ;set;}
public IList<BVDO> bcollection { get ; set ;}
}
Public Class BVDO
{
public xyz {get ; set;};
public IList<CVDO> {get ; set;};
}
I am binding AVDO to my view and I could get the values displayed on my view. But when I do a submit : postback.. I get the object bcollection as null.
Please note: I have done the binding of the objects in the respective VOD's.
Able to get the values for name in AVDO but not for bcollection.
Can anyone let me know what have gone wrong here or is there any solution for it.
Thanks,
Sudhir
ASP net mvc 2
ignatandrei
All-Star
134929 Points
21622 Posts
Moderator
MVP
Re: Getting VDO null on postback on submit button in MVC controller
Feb 03, 2011 12:24 PM|LINK
How can you display?
If dropdown, then re-bind the bCollection
If collection of textboxes, then http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx
In any case, please show the view and the Http[Get|Post} actions
sachingusain
Star
8786 Points
1702 Posts
Re: Getting VDO null on postback on submit button in MVC controller
Feb 03, 2011 01:12 PM|LINK
It would be nice if you can show us some code for view and controller so that we can comment.
This may be a good case for having a custom model binder in place.
A sample here: http://www.dotnetcurry.com/ShowArticle.aspx?ID=584
http://www.hanselman.com/blog/SplittingDateTimeUnitTestingASPNETMVCCustomModelBinders.aspx
Thanks.
francesco ab...
All-Star
20912 Points
3279 Posts
Re: Getting VDO null on postback on submit button in MVC controller
Feb 03, 2011 04:37 PM|LINK
Default model binder is able to read back everything if the right name convention is used in your input fields, and if you don't need to perform delete and insert of list items and all fields are displayed in input fields without "holes", that is without items in the collection that are for instance rendered in display mode and not in input fields.
If you are in the condition above you need only to take kare of using right names, if not, the problem becomes quite difficult and you might consider using some DataGrid that do all the job for you.
Mvc Controls Toolkit | Data Moving Plug-in Videos