I want a controller action “ProfessorStatus” which queries “Professor” table and returns list of active professors for a particular school.
Here is the controller action I have, I am struggling with parameterizing the “School” columns
public ActionResult ProfessorStatus(string schoolType)
{
var activeProfessors = (from p in prof.ProfessorTable.Where(a => a.Engineering.Value == true)
group p by p.ProfessorID into g
select g.Key).ToList();
return View(activeProfessors);
}
Now, In the above controller action. Instead of hard coding “Engineering” I want to parameterize it with “schoolType”.
So if I pass schoolType = Medicine Then the controller will display professors from medicine school and so on for other school types.
How can I avoid hardcording here? Thanks in advance.
If you are not in a position to redesign your whole database and the systems that use it, you can still get around this by using expressions.