NerdDinner Visual Web Developer 2010设置

时间:2010-05-07 11:35:03

标签: asp.net-mvc visual-studio-2010 error-handling nerddinner

我正在按照NerdDinner教程的步骤进行操作。在晚餐Model类中,我有CRUD的错误和验证处理,而不是浏览器中的错误通知,我得到一些调试器对话框。这是为什么? alt text http://img196.imageshack.us/img196/8742/capturehz.png

2 个答案:

答案 0 :(得分:0)

您需要处理控制器中的错误。

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

}

答案 1 :(得分:0)

我认为代码就在那里:

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

您需要将其更改为仅将模型传递回View。

,而不是抛出应用程序异常

ModelState对象应该具有必要的值,如果视图中有Validation消息控件,则应该看到错误消息。