The item doesn't get saved. Only member gets saved.
When I debug [AcceptVerbs(HttpVerbs.Post)] the information is empty in the Item. Why? How should I solve this?
When it goes to the post method of create, then the ITEM dosen't follow the member. and the ITEMS doesn't get saved. I debug the information and there are 0 Number items. Why doesn't it save Items also when I press the button.
Only the member item gets saved.
public class ClassifiedsFormViewModel
{
IClassifiedsRepository classifiedsRepository = new ClassifiedsRepository();
public Member Member { get; private set; }
public SelectList Municipalities { get; private set; }
public ClassifiedsFormViewModel(Member member)
{
Member = member;
Municipalities = new SelectList(classifiedsRepository.GetMunicipalities()
,"MunicipalityId", "Municipality1");
}
}
public ActionResult Create()
{
Member member = new Member();
Item item = new Item();
member.Items.Add(item);
return View(new ClassifiedsFormViewModel(member));
}
//
// POST: /Items/Create
[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));
}
}