2014-10-30 36 views
-4

我正在使用contoso大學wb應用程序。但我無法捕捉到這個錯誤。無法嘗試/發現錯誤

控制器:

public ActionResult Create(Student student) 
     { 
      try 
      { 
       if (ModelState.IsValid) 
       { 
        studentService.Add(student); 
        studentService.Update(student); 
        return RedirectToAction("Index"); 
       } 
      } 
      catch (DataException /* dex */) 
      { 
       //Log the error (uncomment dex variable name and add a line here to write a log. 
       ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); 
      } 
      return View(student); 
     } 

這是錯誤的圖像:

https://www.dropbox.com/s/2sw5gor3x2d1lpi/111111.jpg?dl=0

+1

你是什麼意思_cant catch the error_。你已經發現了錯誤,並在'catch'塊中添加了消息並返回了視圖來顯示它! – 2014-10-30 20:22:24

回答

1

其實你正趕上錯誤! 這就是爲什麼您的錯誤信息"Unable to save changes. Try again, and if the problem persists see your system administrator."會在瀏覽器中正常顯示並且沒有運行時錯誤說明發生了異常。

相關問題