I have a view and inside I create a list, but I can not successfully pass it to the controller without fields that are null:
code in my view:
@using (Html.BeginForm("AddFOP", "Revenue", null, FormMethod.Post, new { enctype = "multipart/form-data" })) { <table class="grid" style="margin-top: 15px"> <thead> <tr> <th>FOP</th> <th>ORGN</th> <th>PROGRAM</th> <th>PERCENTAGE</th> <th></th> </tr> </thead> <tbody> @for (int i = 0; i < Model.editBillingFOPList.Count;i++ ) { <tr> <td>@Html.TextBox("FOPList[" + @i + "].Fund", Model.editBillingFOPList[i].Fund)</td> <td>@Html.TextBox("FOPList[" + @i + "].ORGN", Model.editBillingFOPList[i].ORGN)</td> <td>@Html.TextBox("FOPList[" + @i + "].Program", Model.editBillingFOPList[i].Program)</td> <td>@Html.TextBox("FOPList[" + @i + "].Percentage", Model.editBillingFOPList[i].Percentage)</td> </tr>
this is the controller:
[HttpPost] public ActionResult AddFOP(List<BillingFOPModel> FOPList) { return View(); }
my FOPList shows the number 1, and if I expand it in debug mode, it displays a list of the model, but with zero values โโ- any thoughts?
My model:
public class BillingFOPModel { public string BillingArea; public string BillingAreaName; public string Fund; public string ORGN; public string Program; public string Percentage; }
This is my ViewModel:
public class EditBillingViewModel { //declare attributes public List<BillingFOPModel> editBillingFOPList { get; set; } public string newBillingArea { get; set; } public string newBillingAreaName { get; set; } public string newFund { get; set; } public string newORGN { get; set; } public string newProgram { get; set; } public string newPercentage { get; set; } public EditBillingViewModel() { } //constructor that passes a list and 2 strings public EditBillingViewModel(List<BillingFOPModel> editBillingFOPList, string newBillingArea, string newBillingAreaName) { this.editBillingFOPList = editBillingFOPList; this.newBillingArea = newBillingArea; this.newBillingAreaName = newBillingAreaName; }
c # model-view-controller asp.net-mvc
idreamgeek
source share