So, I have a class that has a List . I pass it in the form as below:
[HttpGet] [Authorize(Roles="user")] [CustomChecker] public ActionResult Index(int? page, int id=0) { EmployeeContext emp = new EmployeeContext(); student st = emp.students.Single(x=>x.id ==id); @ViewBag.id = st.id; return View(st.subjSel.ToPagedList(page ?? 1, 4)); }
And then the view will receive it as follows:
@using PagedList; @using PagedList.Mvc; @model PagedList<MvcApplication6.Models.subject> <div style="font-family:Arial"> <fieldset> <legend><h3>Open Classes</h3></legend> @using (Html.BeginForm("Test", "Enrollment")) { <input type="hidden" name="id" value="@ViewBag.id" /> <table border="1"> <tr> <th>@Html.LabelFor(model => model[0].subj)</th> <th>@Html.LabelFor(model => model[0].days)</th> <th>@Html.LabelFor(model => model[0].cstart)</th> <th>@Html.LabelFor(model => model[0].cend)</th> <th>@Html.LabelFor(model => model[0].professor)</th> <th>@Html.LabelFor(model => model[0].units)</th> <th>@Html.CheckBox("test") Select all</th> </tr> @for (int i = 0; i < Model.Count; i++) { <tr> @Html.HiddenFor(model => model[i].id) <td> @Html.DisplayFor(m => m[i].subj) @Html.HiddenFor(m => m[i].subj) </td> <td> @Html.DisplayFor(m => m[i].days) @Html.HiddenFor(m => m[i].days) </td> <td> @Html.DisplayFor(m => m[i].cstart) @Html.HiddenFor(m => m[i].cstart) </td> <td> @Html.DisplayFor(m => m[i].cend) @Html.HiddenFor(m => m[i].cend) </td> <td> @Html.DisplayFor(m => m[i].professor) @Html.HiddenFor(m => m[i].professor) </td> <td> @Html.DisplayFor(m => m[i].units) @Html.HiddenFor(m => m[i].units) </td> <td> @Html.CheckBoxFor(m => m[i].isSelected) </td> </tr> } </table> <br /> <br /> <table> <tr><td align="center" width="500px"></td></tr> <tr> <td align="center" width="500px"> <input type="submit" value="submit" /> | <input type="button" value="clear" /> </td> </tr> </table> <br /> <br /> } </fieldset> </div> @Html.PagedListPager(Model, page => Url.Action("Index", "Enrollment", new { page, id = Request.QueryString["id"] }))
My problem is that it will display as [0].subj , and this will not allow me to communicate, because it should be something like name[0].subj .
I experimented and tried new methods, do I have ways to link them correctly? I want to use Html Helpers and as much as possible, I do not want to re-implement custom for this part only.
This is the function in which they should be connected. This class has a List students (the one I converted to IPagedList)
[HttpPost] [Authorize(Roles="user")] public ActionResult Test(student st)
And this is what my View looks like. I use CheckBoxFor to select. 
Additional question: Why does my navigation look so ugly?
source share