I have a controller action which returns StudentID.
[HttpPost()]
public ActionResult DisplayStudents()
{
StudentDataContext db = new StudentDataContext ();
var StudentID = (from s in db.vwStudents.Where(s => s.StudentID != null)
group s by s.StudentID into g
select g.Key).ToList();
return Json(new {StudentID});
}
I want to return “StudentName” from the same view as well, but parse the final result and return “StudentID – StudentName” for e.g. “JD11212 – John Deat”
Is there a way where I can group two columns “StudentID” and “StudentName” in one and return that?
This will create a new anonymous type {StudentID, StudentName} which should be what you are looking for.