How can I get datable to work with hidden fields in my view?
How can I get datable to work with hidden fields in my view?
CloudyKoper
Posts: 8Questions: 0Answers: 0
Hi all. I’m hoping that you can help me with this one. I have in my view a bunch of hidden fields which I use in the controller. I want to wrap my table into a jquery datable. When I use this line in the script, $("table").dataTable(), the debugger stops in the controller where I noticed that only the fields that are between my tags are in my formCollection. If I don’t use dataTable() everything works as I expect it to where I have access to all the hidden fields as well as the fields in the tags.
Question: How can I get the jquery datatable to work with my hidden fields as well as the fields in my tags?
Here’s my view:
@model SchoolIn.ViewModels.InstructorIndexData
@using SchoolIn.Models
@{
ViewBag.Title = "Today's Class";
}
$(document).ready(function () {
$("#date").datepicker();
$("table").dataTable();
});
@DateTime.Now.DayOfWeek's Attendance
Select attendance history
@{
string day = DateTime.Now.ToShortDateString();
@Html.TextBox(name: "date", value: day, htmlAttributes: new { id = "date", @class = "TextBoxCss" }) @*navigatinal attributes may be needed later but not for displaying data in input field*@
}
@Html.ActionLink("Select", "ClassAttendance", "Attendance", new { rows = Model.Enrollments.Count(), currentDate = day, id = @ViewBag.ID, teacher = HttpContext.Current.Session["sTeacher"], courseID = HttpContext.Current.Session["sCourseID"] }, null)
@using (Html.BeginForm("ClassAttendance", "Attendance", new { rows = Model.Enrollments.Count(), currentDate = day, id = @ViewBag.ID, teacher = HttpContext.Current.Session["sTeacher"], courseID = HttpContext.Current.Session["sCourseID"] }, FormMethod.Post))
{
var attend = new Enrollment();
@Html.ValidationSummary(true)
Students Enrolled in @ViewBag.teacherName's @ViewBag.courseTitle class
Reports
First Name
Last Name
Grade
Attendance Code
Class Day
@foreach (var item in Model.Enrollments)
{
@Html.HiddenFor(modelItem => item.EnrollmentID)
@Html.HiddenFor(modelItem => item.Assignment)<!--navigational-->
@Html.HiddenFor(modelItem => item.Course.Title)
@Html.HiddenFor(modelItem => item.CourseID)
@Html.HiddenFor(modelItem => item.Date)
@Html.HiddenFor(modelItem => item.dayOfWeek)
@Html.HiddenFor(modelItem => item.Instructor)
@Html.HiddenFor(modelItem => item.StudentID)
@Html.HiddenFor(modelItem => item.Student.Address)
@Html.HiddenFor(modelItem => item.Student.CourseID)
@Html.HiddenFor(modelItem => item.Student.Courses)<!--Navigational-->
@Html.HiddenFor(modelItem => item.Student.EnrollmentDate)
@Html.HiddenFor(modelItem => item.Student.Enrollments)<!--Navigational-->
@Html.HiddenFor(modelItem => item.Student.FullName)
@Html.HiddenFor(modelItem => item.Student.InstructorID)
@Html.HiddenFor(modelItem => item.Student.Instructors) <!--Navigational-->
@Html.HiddenFor(modelItem => item.Student.StudentID)
@Html.ActionLink("Report", "PrintCustomers", "PdfRender", new { sName = item.Student.FirstMidName, courseTitle = item.Course.Title, sNumber = item.Student.StudentNum, instructorName = HttpContext.Current.Session["teacherName"] }, null)
@Html.EditorFor(modelItem => item.Student.FirstMidName)
@Html.EditorFor(modelItem => item.Student.LastName)
@*Html.Action("GetGrade", "Grade", new { date = DateTime.Now, StudentID=6 })*@
@Html.EditorFor(modelItem => item.Grade)
@Html.TextBoxFor(modelItem => item.attendanceCode, new { Value = "1" })
@*Html.ValidationMessageFor(model => model.Enrollments.FirstOrDefault().attendanceCode)*@
@Html.EditorFor(modelItem => item.classDays)
}
}
Question: How can I get the jquery datatable to work with my hidden fields as well as the fields in my tags?
Here’s my view:
@model SchoolIn.ViewModels.InstructorIndexData
@using SchoolIn.Models
@{
ViewBag.Title = "Today's Class";
}
$(document).ready(function () {
$("#date").datepicker();
$("table").dataTable();
});
@DateTime.Now.DayOfWeek's Attendance
Select attendance history
@{
string day = DateTime.Now.ToShortDateString();
@Html.TextBox(name: "date", value: day, htmlAttributes: new { id = "date", @class = "TextBoxCss" }) @*navigatinal attributes may be needed later but not for displaying data in input field*@
}
@Html.ActionLink("Select", "ClassAttendance", "Attendance", new { rows = Model.Enrollments.Count(), currentDate = day, id = @ViewBag.ID, teacher = HttpContext.Current.Session["sTeacher"], courseID = HttpContext.Current.Session["sCourseID"] }, null)
@using (Html.BeginForm("ClassAttendance", "Attendance", new { rows = Model.Enrollments.Count(), currentDate = day, id = @ViewBag.ID, teacher = HttpContext.Current.Session["sTeacher"], courseID = HttpContext.Current.Session["sCourseID"] }, FormMethod.Post))
{
var attend = new Enrollment();
@Html.ValidationSummary(true)
Students Enrolled in @ViewBag.teacherName's @ViewBag.courseTitle class
Reports
First Name
Last Name
Grade
Attendance Code
Class Day
@foreach (var item in Model.Enrollments)
{
@Html.HiddenFor(modelItem => item.EnrollmentID)
@Html.HiddenFor(modelItem => item.Assignment)<!--navigational-->
@Html.HiddenFor(modelItem => item.Course.Title)
@Html.HiddenFor(modelItem => item.CourseID)
@Html.HiddenFor(modelItem => item.Date)
@Html.HiddenFor(modelItem => item.dayOfWeek)
@Html.HiddenFor(modelItem => item.Instructor)
@Html.HiddenFor(modelItem => item.StudentID)
@Html.HiddenFor(modelItem => item.Student.Address)
@Html.HiddenFor(modelItem => item.Student.CourseID)
@Html.HiddenFor(modelItem => item.Student.Courses)<!--Navigational-->
@Html.HiddenFor(modelItem => item.Student.EnrollmentDate)
@Html.HiddenFor(modelItem => item.Student.Enrollments)<!--Navigational-->
@Html.HiddenFor(modelItem => item.Student.FullName)
@Html.HiddenFor(modelItem => item.Student.InstructorID)
@Html.HiddenFor(modelItem => item.Student.Instructors) <!--Navigational-->
@Html.HiddenFor(modelItem => item.Student.StudentID)
@Html.ActionLink("Report", "PrintCustomers", "PdfRender", new { sName = item.Student.FirstMidName, courseTitle = item.Course.Title, sNumber = item.Student.StudentNum, instructorName = HttpContext.Current.Session["teacherName"] }, null)
@Html.EditorFor(modelItem => item.Student.FirstMidName)
@Html.EditorFor(modelItem => item.Student.LastName)
@*Html.Action("GetGrade", "Grade", new { date = DateTime.Now, StudentID=6 })*@
@Html.EditorFor(modelItem => item.Grade)
@Html.TextBoxFor(modelItem => item.attendanceCode, new { Value = "1" })
@*Html.ValidationMessageFor(model => model.Enrollments.FirstOrDefault().attendanceCode)*@
@Html.EditorFor(modelItem => item.classDays)
}
}
This discussion has been closed.
Replies