간단한 주문 추적 응용 프로그램 인 MVC3 응용 프로그램을 처음 작성했습니다. 주문과 세부 사항을 동시에 수정하고 싶습니다. 주문을 편집 할 때 편집을위한 ActionResult가 주문과 관련 라인을 반환합니다 (나는 EF도 사용하고 있습니다).MVC보기에서 여러 개체 저장
주문 및 행은 아무런 문제없이 표시되지만 페이지를 저장하면 컨트롤러에 다시 전달 된 행이 없습니다. 주문 만. 다음은 View 코드입니다.
@model OrderTracker.Models.Order
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
@using (Html.BeginForm())
{
<fieldset>
<legend>Order</legend>
@Html.HiddenFor(model => model.ID)
@Html.HiddenFor(model => model.UserId)
<div>
@Html.LabelFor(model => model.OrderDate)
</div>
<div>
@Html.EditorFor(model => model.OrderDate)
</div>
<div>
@Html.LabelFor(model => model.Description)
</div>
<div>
@Html.EditorFor(model => model.Description)
</div>
<table>
<tr>
<th>
Description
</th>
<th>
Quantity
</th>
<th>
Weight
</th>
<th>
Price
</th>
<th></th>
</tr>
@foreach (var line in Model.OrderLines)
{
<tr>
<td>
@Html.EditorFor(modelItem => line.Description)
</td>
<td>
@Html.EditorFor(modelItem => line.Quantity)
</td>
<td>
@Html.EditorFor(modelItem => line.Weight)
</td>
<td>
@Html.EditorFor(modelItem => line.Price)
</td>
</tr>
}
</table>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
라인 데이터와 주문 데이터를 저장하는 가장 좋은 방법에 대한 지침을 얻을 수 있습니까?
감사합니다.
ASP MVC 5에서 작동하지 않았습니다. 모든 포인터는 일괄 처리 Ienumerable을 보내주십시오. –
transformer
@transformer는 MVC5에서 정상적으로 작동합니다. 너를 위해 무엇이 실패하고 있는가? 'Order'모델에는 'OrderLine'항목의 목록이 있습니다. 내 답변에 포인트 1 & 3에 세심한주의를 기울이십시오. github 저장소에 샘플 코드가 있습니까? –