回答

0

你需要處理錯誤的控制器。

public ActionResult Create({YourObject} object) 
{ 
    try 
    { 
    //Try to save your object. 
    } 
    catch(ApplicationException ex) 
    { 
    //Do something with the exception. 
    } 

} 
0

我認爲這是正確的,在代碼:

if (!isValid) 
    throw new ApplicationExcption(...) 

拋出一個應用程序異常相反的,你需要改變,要只通過模型回觀。

的ModelState中的對象應該具有必要的值,如果你有你的觀點的驗證消息的控制,你應該會看到錯誤消息。

相關問題