0
我有一個面板象下面這樣:
如何從視圖傳遞兩個相同的對象到控制器
和視圖代碼是:
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingFour">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseFour" aria-expanded="false" aria-controls="collapseFour">
Product Details
</a>
</h4>
</div>
<div id="collapseFour" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingFour">
<div class="panel-body">
<a class="btn btn-lg btn-primary btn-add-panel" > <i class="glyphicon glyphicon-plus"></i> Add new Product</a>
<div id="propanel"></div>
<br />
<div class="panel panel-default template" >
<div class="panel-heading">
<span class="glyphicon glyphicon-remove-circle pull-right "></span>
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse5">
New Product
</a>
</h4>
</div>
<div id="collapse5" class="panel-collapse collapse">
<div class="panel-body">
<div class="form-group">
@Html.LabelFor(model => model.JobProduct.Detail, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.JobProduct.Detail, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.JobProduct.Detail, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.JobProduct.UnitPrice, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.JobProduct.UnitPrice, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.JobProduct.UnitPrice, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.JobProduct.Count, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.JobProduct.Count, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.JobProduct.Count, "", new { @class = "text-danger" })
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
此面板這倆一個產品或更多。在viewmodel
我得到一個產品類型的對象。我想創建插入產品的view
列表,並將其傳遞給控制器列表。實際上,我想在視圖中創建列表並在其中添加對象。
我如何獲得產品插入並作爲清單發送至controller
?
參見[這個答案](http://stackoverflow.com/questions/28019793/submit-same-partial-view-called-multiple-times-data-to-controller/28081308#28081308)的一些選項 –
@StephenMuecke感謝您的答覆。我使用了該解決方案及其工作,但它傳遞了正確的計數,但爲空contains.do你知道爲什麼嗎? – Mojtaba
然後你的代碼是不正確的 - 你沒有顯示你所做的,所以我不能猜測:) –