Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

C#
@Html.LabelFor(model => model.PurchaseOrder.PurchaseOrderDate)
                                  @Html.TextBoxFor(model => model.PurchaseOrder.PurchaseOrderDate, "", new { @class = "form-control" })

C#
<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 ]
C#
<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:
SQL
public ActionResult Purchaseform(int id = 0)
       {
 PurchaseOrder Purchase = new PurchaseOrder();
PurchaseOrder.PuchaseOrderTax = new ObservableCollection<PuchaseOrderTax>() { new PuchaseOrderTax()} 
 return View(Purchase);
}



SQL
[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.

SQL
[HttpGet]
       public ActionResult AddNewRow(int finUid)
       {
           
               return View("~/Views/PartialView/Purchase/PurchaseTax.cshtml", new PuchaseOrderTax() { Uid = Uid++});
       }
Posted
Updated 14-Sep-14 17:20pm
v2
Comments
[no name] 14-Sep-14 20:40pm    
You might try editing your question to make it an actual question. You posted your entire question in the title section and it gets cut off there so that people can't read it.
Mihir_Naik 14-Sep-14 23:16pm    
ok, Thank you! i will Correct it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900