I have a View that has a list of Blocks which are rendered using an EditorFor helper. That helper draws BlockItems inside it using editorfor.
Firstly I had to add a for(int .... loop to get the items to be read when posting which now is working. The problem is adding new BlockItems using ajax. I then return a rendered view that used the editorfor template for a BlockItem. However then it does
not get the proper naming which is something like this: Block[1].BlockItems[2] and does not get interpreted by the model reader. How can this be achieved?
What I have done is to actually use javascript to rename the blockitems Id's but well, that is NOT smoth. Is there a way to do this more efficiently/more correctly?
Now I use my container class and have basically "empty" views that just: for(....) type A which renders Type B for loop for editorfor for Type C. Not very clean.
Todilo
Member
4 Points
7 Posts
Ajax add item not read by default model reader
Nov 24, 2012 06:59 AM|LINK
I have a View that has a list of Blocks which are rendered using an EditorFor helper. That helper draws BlockItems inside it using editorfor.
Firstly I had to add a for(int .... loop to get the items to be read when posting which now is working. The problem is adding new BlockItems using ajax. I then return a rendered view that used the editorfor template for a BlockItem. However then it does not get the proper naming which is something like this: Block[1].BlockItems[2] and does not get interpreted by the model reader. How can this be achieved?
What I have done is to actually use javascript to rename the blockitems Id's but well, that is NOT smoth. Is there a way to do this more efficiently/more correctly?
Using MVC 4
ignatandrei
All-Star
134521 Points
21576 Posts
Moderator
MVP
Re: Ajax add item not read by default model reader
Nov 24, 2012 10:54 AM|LINK
I used to do this by using a Model that have lines with fake null and a not null line to be displayed.
Todilo
Member
4 Points
7 Posts
Re: Ajax add item not read by default model reader
Nov 26, 2012 08:09 PM|LINK
Do you have an example you could show?
Now I use my container class and have basically "empty" views that just: for(....) type A which renders Type B for loop for editorfor for Type C. Not very clean.