当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net mvc - MVC child - parent on the same page

问题描述:

I'm pretty new to using MVC3 so hopefully the terms I'm using are all correct.

Basically I'm looking for a way (if possible!) to have a parent and child(s) record be added on the same page. I'm able to get the page to display correctly, but I'm unsure how to update the parent model.

In my Create view I have all the fields for the parent, and I'd also like to add the child records to the form as well.

I'm currently using Html.RenderPartial("CreateChildView") to display my Create child page within the parent.

I'm also using Html.RenderPartial("IndexChildView) to display my child records that have been added.

Where I'm stuck at is how to update the Parent model from the "CreateChildView" from above,

I've tried adding a submit button to the child view but I'm not getting the results I was hoping for.

the equivelent c# code that I'm kind of looking for is:

ParentObject.ChildObject.Add(new ChildObject)

and then a way to display this correctly

Thanks in Advance

网友答案:

Place both partials in div with ids. Post data with ajax from "CreateChildView" and update "IndexChildView" with response.

分享给朋友:
您可能感兴趣的文章:
随机阅读: