컨트롤러에 수량 속성 게시 (편집 작업). SQL 데이터베이스에서 ProductSet과 연결된 OrderedProductSet을 편집 중입니다 (이름과 가격이 표시됩니다). 보기에서 컨트롤러로 여러 데이터를 전달하는 방법? 데이터를 받기 위해 컨트롤러 클래스에 메서드를 작성하는 방법 (이 특정 경우에 메서드 인수에 대해 묻습니다).뷰에서 컨트롤러로 MVC
내보기 : (물론 분리 된 클래스에서)
@model [email protected]{
ViewBag.Title = "Edycja zamówienia";
}
<h2>Edycja zamówienie</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<table class="table">
<tr>
<th>
<b>Nazwa produktu</b>
</th>
<th>
<b>Cena</b>
</th>
<th>
<b>Ilość</b>
</th>
<th></th>
</tr>
@foreach (var item in Model.orderedProductSet)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ProduktSet.name)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProduktSet.price)
</td>
<td>
@Html.EditorFor(model => item.quantity, new { htmlAttributes = new { @class = "form-control" } })
</td>
</tr>
}
</table>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Potwierdź zmiany" class="btn btn-default" />
</div>
</div>
}
<div>
@Html.ActionLink("Powrót", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
내 모델 :
public class ProductViewModel
{
public OrderSet orderSet { get; set; }
public IEnumerable<OrderedProductSet> orderedProduktSet { get; set; }
}
public partial class OrderedProduktSet
{
public int orderNumber{ get; set; }
public int productNumber { get; set; }
public int ilosc { get; set; }
public virtual ProduktSet ProduktSet { get; set; }
public virtual OrderSet OrderSet { get; set; }
}
질문의 문구를 변경해야합니다. 기술적으로, 뷰는 절대로 컨트롤러에 데이터를 보내지 않습니다 (이런 식으로). 아마도'컨트롤러 메소드에 여러 데이터 포인트를 게시하는 방법'을 준비해야합니다. –
@ErikPhilips가 변경했습니다. 감사합니다. –