Click here to Skip to main content
15,888,111 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have been a developer for many years non of which have been on web front end

So i decieded to tackle one of the items on my "wanna know" list. this time it's mvc3

i am attempting to create simple crud for this objet( below ) but am stuck on the "MyItems" list.
I am looking for the create / edit to be created with one operation for both the MyClass properties + ( adding the line items for MyItems ).

so far i've attemnpted to create a partial view which uses jquery to clone nodes to create a single item for MyItems and include that partial view in my Create view. however i am not getting the objet binding correct for when i submit the save, MyItems is always empty.

Any pointers and links to tutorials etc on the matter are greatly
appreciated

Advice and solutions welcome as well

C#
public class MyClass
{
    public MyClass()
    {
        MyItems = new List<MyItem>();
    }

    [Required]
    public string Name { get; set; }
    public int Age { get; set; }

    public List<MyItem> MyItems { get; set; }

    public class MyItem
    {
        public string Lable { get; set; }
        public string Value { get; set; }
    }
}
Posted
Comments
Sergey Alexandrovich Kryukov 2-Aug-12 13:01pm    
Do you have a question?
--SA
cechode 2-Aug-12 13:20pm    
yeah :) "MyItems is always empty" i am looking for the appropriate way to get a list of myitems with the main object (myclass) back to the server to that i can store it. as of now the value of MyItems is always an empty list. ( do you know where i can find a tutorial that explains this a bit? ( everything i saw so far only deals with a simple object with string/int/date properties. or a master detail scenario ( which this is not )
Kenneth Haugland 2-Aug-12 14:54pm    
You'll have to add items to the list if its not supposed to be empty....
Sergey Alexandrovich Kryukov 2-Aug-12 15:58pm    
Exactly.
--SA
Sergey Alexandrovich Kryukov 2-Aug-12 15:59pm    
What is Lable? If you misspell in code, it resists...
--SA

1 solution

Is this your ViewModel ? The easiest way to do this with MVC3, is to use the @Html.XXXFor methods to create appropriate controls to show your data, and then it will populate them on postback. I prefer to use AJAX and JSON, in which case you build your objects in javascript, but if you are happy to do postbacks, let the framework do it for you. Please explain how 'myclass' gets in to your view and how your view deals with it, and I'll be happy to answer more.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900