tags:

views:

54

answers:

3

In my Database I have Members Table and Pictures tables. A Member can have 1 to many Pictures. When Post has been made the member.Picture.Count = 0, I can't understand Why? and How should I solve this?

What Iam doing is:

    public ActionResult Create()
    {

        Member member = new Member();
        Picture pic = new Picture();
        member.Pictures.add();

        return View(new ClassifiedsFormViewModel(member));
    }

//POST:

[AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(Member member) {

        if (ModelState.IsValid)
        {

            try
            {
                classifiedsRepository.Add(member);
                classifiedsRepository.Save();

                return RedirectToAction("Create", new { id = member.MemberId });
            }
            catch
            {
                ModelState.AddModelErrors(member.GetRuleViolations());
            }
        }

        return View(new ClassifiedsFormViewModel(member));
    }
A: 

From what code you have provided the only thing I can see is where you're calling member.Pictures.add you're not actually passing anything in. Therefor nothing is getting added to the pictures collection.

Chad Moran
A: 

ohh sorry i wrote it by hand and I forgot to write the whole code. But I should be like this. But still it dosen't work. Can someone help me out?

    public ActionResult Create()
    {

        Member member = new Member();
        Picture pic = new Picture();
        member.Pictures.add(pic);

        return View(new ClassifiedsFormViewModel(member));
    }
Frajer
Stackoverflow does not work like a forum. You can edit your original post, rather than posting an "answer".
Jon B
A: 

I have same problem. I have tried with entites and it dosen't work.

Has some tried this out. this should be simple.