I am new in MVC. I display the parent view details in two parts, the details and a list of child. But now I want add the possibility to add an other child to this parent in the same view. I use : controller
public ViewResult Details(long id)
{
Parent x = db.Parent.Find(id);
return View(x);
}
view :
@model MyProject_v0_2.Models.Parent
<table id="details">
....
</table>
<table id="lstChild">
@foreach (var item in Model.Child)
{...}
</table>
I want add a button here which let me add a child in this view. I can add a table that I display or not with all the child data, but I don't know I to save it. In the future I will need to change some Parent properties so I can't change the model type.
Thanks,
Checkout the following article which illustrates a nice way of how to achieve this task. It uses javascript on the client to add/delete rows. It also uses a custom Html.BeginCollectionItem
helper which allows for generating non sequential indexes for the collection input field names.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.