我想要做的是從控制器內調用警報對話框。 推理是因爲控制器被視圖通過ajax調用調用,並且不會重新加載頁面,因此將無法比較tempdata中的任何新數據或其他。從控制器調用警報框
該行爲的目的是檢查入學的學生是否應該在那裏。如果課程不在他們的時間表中,那麼權限布爾仍然是錯誤的,並且會彈出一個警告,聲明學生不在課堂中。
public ActionResult Action(string ccod, int sid)
{
IEnumerable<MvcStudentTracker.Databases.Course> result = from course in db.Courses
join sched in db.Schedules on course.CourseCode equals sched.ClassCode
where sched.StuID == sid
select course;
bool permission = false;
foreach (var item in result)
{
if (item.CourseCode == ccod)
permission = true;
}
if (permission == false)
{
//call alert dialog box "This student is not signed up for this class"
}
return null;
}
爲什麼不能用'permission'狀態,然後在你的Ajax調用成功使用該值返回'JsonResult'顯示警報? –
或者,如果你真的想,只需設置一個ViewBag變量並在聲明你的JS函數來顯示對話框時使用它。 – user1477388
因爲我是mvc的新手,不知道這是一個選項。我會試一試。謝謝。 – RSpraker