Problem
I need to search by ClassID,SectionID,InstructorID DROPDOWNLISTS and i can have options if one drop down have null value or not
search i need is (classID =NULL OR NOT)AND (sectionid =null or not)AND(InstructorID=Null or not)
I only can search by one drop down menu InstructorID BUT SECTIONID,ClassID Dropdown how to do that .
I have Model schedules as following :
- public class Schedule
- {
- [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
- [Key, Column(Order = 0)]
- public int SchedualeID { get; set; }
-
- public int CourseID { get; set; }
-
- [DisplayName("InstructorName")]
- public int InstructorID { get; set; }
-
- public int SectionID { get; set; }
-
- public int ClassID { get; set; }
-
- public int DayNum { get; set; }
-
- [DataType(DataType.Date)]
- [DisplayFormat(DataFormatString =
- "{0:dd-MM-yyyy}",
- ApplyFormatInEditMode = true)]
- [Required]
- public DateTime? FromDate { get; set; }
- [DataType(DataType.Date)]
- [DisplayFormat(DataFormatString =
- "{0:dd-MM-yyyy}",
- ApplyFormatInEditMode = true)]
- [Required]
- public DateTime? ToDate { get; set; }
-
- [ForeignKey("ClassID")]
- public virtual Class classes { get; set; }
- [ForeignKey("SectionID")]
- public virtual Section section { get; set; }
- [ForeignKey("DayNum")]
- public virtual Calender calender { get; set; }
- public virtual Instructor instructores { get; set; }
- public virtual Courses courses { get; set; }
- }
- }
This schedule model have foreign key for more tables as Class,Section,Instructor,Calender
All these tables have relations with table schedule
I need to get data from schedule based on ClassID,SectionID,InstructorID DROPDOWNLISTS
But i cannot do search by multiple fields
I only can search by InstructorID FIELD
What I try
Index action inside schedule controller
code below working but only InstructorID Drop down not all drop down
- public ActionResult Index()
- {
- ViewBag.InstructorID = new SelectList(db.Instructors, "InstructorID", "InstructorName");
- var schedule = db.schedule.Include(s => s.calender).Include(s => s.classes).Include(s => s.courses).Include(s => s.instructores).Include(s => s.section);
-
- return View(schedule.ToList());
- }
- [HttpPost]
- public ActionResult Index(int InstructorID)
- {
- ViewBag.InstructorID = new SelectList(db.Instructors, "InstructorID", "InstructorName");
- var schedule = db.schedule.Include(s => s.calender).Include(s => s.classes).Include(s => s.courses).Include(s => s.instructores).Include(s => s.section).Where(s=>s.InstructorID==InstructorID);
-
- return View(schedule.ToList());
- }
In view of Index action in schedule controller- <p>
- @Html.ActionLink("Create New", "Create")
- @using (Html.BeginForm())
- {
- <p>
- Title:@Html.DropDownList("InstructorID", null, htmlAttributes: new { @class = "form-control" })<br />
- <input type="submit" value="Filter" />
- </p>
- }
- </p>