, . -, Html- BeginCollectionItem. , / , .
( ).
Course. Ctor of course -.
RenderPartial partailview + .
@foreach(var student in Model.Students)
{
RenderPartial("_Student", student);
}
:
@model Project.Data.Entities.Student
<div class="AddStudent form-group">
@using (Html.BeginCollectionItem("students"))
{
@Html.Label("Name:", new { @class = "control-label col-md-2" })
<div class="col-md-8">
@Html.TextBoxFor(x => x.Name)
<button type="button" class="deletButton btn btn-default">Remove</button>
@Html.ValidationMessageFor(model => model.Name)
</div>
}
</div>
, , (jquery) .
, ajax "_Student".
<div>
@Ajax.ActionLink("Add more...", "NewStudentRow", "Course", new AjaxOptions()
{
InsertionMode = InsertionMode.InsertAfter,
UpdateTargetId = "students"
}, new { @class = "btn btn-default" })
</div>
NewStudentRow :
public PartialViewResult NewStudentRow ()
{
return PartialView("_Student", new Student());
}
, http://www.nuget.org/packages/BeginCollectionItem/