Arul Jesuraj

Arul Jesuraj

  • 1.6k
  • 109
  • 22.5k

How to send marks from student marks entry view to controlle

Jun 26 2014 3:38 AM

Hi,

I've a mark entry view where view is looped and constructed from studentmarks Model of list of students.

Below is my model:

public class StudentMarks
{
public List<MarkEntry> MarksList { get; set; }
}

public class MarkEntry
{
public int StudentId { get; set; }
public string StudentName { get; set; }
public List<SubjectList> lstSubject { get; set; }
}

public class SubjectList
{
public int SubjectId { get; set; }
public string SubjectName { get; set; }
public decimal MaxMark { get; set; }
public decimal ObtainedMark { get; set; }
}

My view looks below:

<table class="table table-bordered">
<tr style="background-color:#573D7D; color:#FFF">
<th>Student Id</th>
<th>Student Name</th>
@foreach (var item in Model.MarksList)
{
<th>@item[0].SubjectName</th>
}
</tr>
@foreach (var list in Model.MarksList)
{
<tr>
@{ int i = 0; }

<td>@Html.DisplayFor(x => x.MarksList[i].StudentId)</td>
<td>@Html.DisplayFor(x => x.MarksList[i].StudentName)</td>
@foreach (var item in @list.lstSubject)
{
<td>@Html.TextBoxFor(x => x.Subjects[i].ObtainedMark)</td>

i++;
}
</tr>
}
</table>


Now, when I try to insert these values, in controller I get only first row textbox values. I'm not getting entire model with data as list.

How to solve this?