public JsonResult CoursesGetById(int id = 1) { if (db.Courses.Find(new object[] { id }) != null) { return Json(from x in db.Courses where x.CourseID == id select new { CourseID = x.CourseID, StudyID = x.Study.StudyID, Name = x.Name }, JsonRequestBehavior.AllowGet); } Course data = new Course { CourseID = -1, Study = null, Name = "Nepostojeći kolegij" }; return Json(data, JsonRequestBehavior.AllowGet); }
// Methods public JsonResult CoursesByStudyID(int id = 1) { if (db.Studies.Find(new object[] { id }) != null) { return Json(from o in db.Courses where o.Study == db.Studies.FirstOrDefault<Study>(s => (s.StudyID == id)) select o, JsonRequestBehavior.AllowGet); } Course data = new Course { CourseID = -1, Name = "Nepostojeći studij", Study = null }; return Json(data, JsonRequestBehavior.AllowGet); }