MVC List Post Back

Hi experts,

Pls find my View

@for (var i = 0; i < Model.StudyList.Count; i++)
{

<tr>
<td>
@Html.EditorFor(m => m.StudyList[i].Billingname, new { id="txteidtor"})
</td>
<td>
@Html.EditorFor(m => m.StudyList[i].BillingId, new { id = "tt" })

@Html.EditorFor(m => m.StudyList[i].scanamount, new { id = "tt2" })
@Html.EditorFor(m => m.StudyList[i].discountamount, new { id = "tt5" })
@Html.EditorFor(m => m.StudyList[i].NetAmount, new { id = "tt8" })
</td>
<td>

</td>
<td>

</td>
</tr>

}

Pls find my Model

public class StudyDetails
{
public string Billingname { get; set; }
public int BillingId { get; set; }
public float scanamount { get; set; }
public int discountamount { get; set; }
public int NetAmount { get; set; }

}
[Serializable]
public class AppoinmentEntityInfo
{

 public IList<StudyDetails> StudyList { get; set; }

}

Pls find my Controller

//This Controller gives me data

public ActionResult Appointment()
{
AppoinmentEntityInfo obj = new AppoinmentEntityInfo();

obj.StudyList.Add(new StudyDetails() { BillingId = 0, Billingname = "Test Billingname", discountamount = 100, scanamount = 100, NetAmount = 100 });
return View(obj);
}

//This Controller used for getting my data from view

[HttpPost]
public ActionResult Save(AppoinmentEntityInfo ObjAppointmentList)
{

}

But in my controller objappointmentlist.StudyList  length is zero, Pls help me

Change studylist to a list instead of interface so the binder know how to create one on postback.

public List<StudyDetails> StudyList { get; set; }

HI ALL,

It works on this syntax 

@Html.TextBox("ObjAppointmentList.BillingName",
Model.BillingName, new { id = "BillingName" })

what is diffierence between above one

and

    @Html.TextBoxFor(model => model.BillingName, new { id = "Billingname" })

1991hariharan

new { id = "tt2" })

Try removing the id attribute and see whether you get the object

Hi,

Base on your code, I made a test in MVC 5 project and it works fine.

Please try it in a new project.

You may share the project on the OneDrive.

Best Regards

Starain

Leave a Reply