Description: When i post form with two count of puchaseordertax, i will found that but if i post with only one record (Count) it did'nt![Note:Uid is working s index and Correctly! ]
My Model:
class PurchaseOrder
{
int PurchaseOrderID {get;set;}
datetime PurchaseOrderDate {get;set;}
public virtual ICollection<puchaseordertax> PuchaseOrderTax { get; set; }
}
My View:
@model PurchaseOrder
@Html.LabelFor(model => model.PurchaseOrder.PurchaseOrderDate)
@Html.TextBoxFor(model => model.PurchaseOrder.PurchaseOrderDate, "", new { @class = "form-control" })
<table class="table table-bordered">
<thead>
<tr>
<th>
Tax
</th>
<th>
OtherCharge </th>
<th width="60px">Action</th>
</tr>
</thead>
<tbody id="ContainerTax">
{
foreach (var itmTax in Model.PurchaseOrder.PuchaseOrderTax)
{
Html.RenderPartial("~/Views/PartialView/Purchase/PurchaseTax.cshtml", itmTax);
}
}
</tbody>
</table>
-----------------------
PartialView [here: Model.Uid = Work as Index which start from 0 to 1,2 3 and so on ]
<tr>
<td>
<input id="PurchaseOrder.PuchaseOrderTax_@(Model.Uid)__Tax" name="PurchaseOrder.PuchaseOrderTax[@Model.Uid].Tax" type="text">
</td>
<input id="PurchaseOrder.PuchaseOrderTax_@(Model.Uid)__OtherCharge" name="PurchaseOrder.PuchaseOrderTax[@Model.Uid].T\OtherCharge" type="text"></td>
-----------------------------
So When i Submit form with two Tax, I Found value but if only one then i didn't.
My Controller:
public ActionResult Purchaseform(int id = 0)
{
PurchaseOrder Purchase = new PurchaseOrder();
PurchaseOrder.PuchaseOrderTax = new ObservableCollection<PuchaseOrderTax>() { new PuchaseOrderTax()}
return View(Purchase);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Draft(PurchaseOrder model)
{
model.PuchaseOrderTax = No Record if Collection is <1
}
---------------------
and also Take a look at on partial View how i add new Row.
[HttpGet]
public ActionResult AddNewRow(int finUid)
{
return View("~/Views/PartialView/Purchase/PurchaseTax.cshtml", new PuchaseOrderTax() { Uid = Uid++});
}