i want to post list back to the controller.
1: i have bind a table from list in partial view.
2: binded list is with a bool variable which is false when list rendered in partial view and after clicking on checkbox that value became change.
3: i am posting it again to the controller to save my record again in database.
But after posting back to the controller list became null.
@model JNCU_Apps.Models.SemesterCenterStudentDetailsModel
@{
ViewBag.Title = "Center Wise Candidate List";
}
<div id="divGrid">
<table>
<thead>
<tr>
<th>Sl. No</th>
<th> </th>
<th>Enrollment No.</th>
<th>Registration No.</th>
<th>Roll No.</th>
<th>Name</th>
<th>Father Name</th>
<th>Date of Birth</th>
<th>college Name</th>
<th>Course Name</th>
</tr>
</thead>
<tbody>
@for (int t = 0; t < Model.studentList.Count; t++)
{
<tr>
<td>@(t = t + 1)</td>
<td>
@Html.HiddenFor(model => Model.studentList[t].candidateId)
@Html.CheckBoxFor(model => model.studentList[t].isAbsent)
@Html.HiddenFor(model => Model.studentList[t].isAbsent)
</td>
<td>@Html.DisplayFor(model => Model.studentList[t].enrollNumber) @Html.HiddenFor(model => Model.studentList[t].enrollNumber) </td>
<td>@Html.DisplayFor(model => Model.studentList[t].registrationNumber) @Html.HiddenFor(model => Model.studentList[t].registrationNumber) </td>
<td>@Html.DisplayFor(model => Model.studentList[t].rollNumber) @Html.HiddenFor(model => Model.studentList[t].rollNumber)</td>
<td>@Html.DisplayFor(model => Model.studentList[t].candidateName)</td>
<td>@Html.DisplayFor(model => Model.studentList[t].fatherName) </td>
<td>@Html.DisplayFor(model => Model.studentList[t].dob) </td>
<td>@Html.DisplayFor(model => Model.studentList[t].collegeName) </td>
<td>@Html.DisplayFor(model => Model.studentList[t].courseName)</td>
</tr>
}
</tbody>
</table>
</div>
this is partial view
function bindStudentList() {
var _exmType = $("#examtype").val();
var _Course = $("#transid").val();
var _Subjectid = $("#Subtransid").val();
var _PaperID = $("#ddlPaperList").val();
$.ajax({
url: '@Url.Action("BindStudentListCenterWise", "Exam")',
data: { exmType: _exmType, course: _Course, Subjectid: _Subjectid, PaperID: _PaperID },
type: 'GET',
dataType: 'HTML'
}).success(function (returndata) {
$('#Div_Data').html(returndata);
}).error(function (xhr, status) {
$('#Div_Data').html('');
})
}
//this is function by which i am binding data
public ActionResult BindStudentListCenterWise(string exmType, string course, string Subjectid, string PaperID)
{
string centerCode = Convert.ToString(Session["collegeCode"]);
AdmissionSemester objSem = new AdmissionSemester();
JNCU_Apps.Models.SemesterCenterStudentDetailsModel model = new JNCU_Apps.Models.SemesterCenterStudentDetailsModel();
model.studentList = objSem.GetSemesterCenterWiseStudentList(exmType, centerCode, course, Subjectid, PaperID);
if (model.studentList != null)
{
return PartialView("_StudentAttendance", model);
}
else
{
return Content("No Record Found");
}
}
//this is action
public ActionResult StudentAttendance(SemesterCenterStudentDetailsModel model)
{
AdmissionSemester objSem = new AdmissionSemester();
ViewBag.Courses = objSem.getCoursesDropDownList();
System.Text.StringBuilder sbQual = new StringBuilder();
sbQual.Append("<StudentAttendance>");
foreach (var s in model.studentList)
{
sbQual.Append("<Attendance>");
sbQual.Append("<candidateId>" + s.candidateId + "</candidateId>");
sbQual.Append("<rollNumber>" + s.rollNumber + "</rollNumber>");
sbQual.Append("<isAbsent>" + s.isAbsent + "</isAbsent>");
sbQual.Append("</Attendance>");
}
sbQual.Append("</StudentAttendance>");
model.CandidateXML = sbQual.ToString();
model.centerCode = Convert.ToString(Session["collegeCode"]);
model.ipAddress = ipAddress.getIPAddress();
var res = objSem.InsertAttendance(model.ExamTypeId, model.CourseId, model.SubjectID, model.PaperID, model.CandidateXML, model.ipAddress, model.centerCode);
if (res.Flag == 1)
{
ViewBag.Msg = res.Msg;
return View();
}
else
{
ViewBag.Msg = res.Msg;
return View();
}
}
//this is post action in which i want to get list again.