我习惯了 C# 和 vb.net winforms,通常只需设置断点并单步执行我的代码就可以找到我需要的所有错误。
我想知道我做错了什么。
我在这里放置一个断点:
public ActionResult Index(int id)
{
var cnty = from r in db.Clients
where r.ClientID == id
select r;
if (cnty != null) // breakpoint here
{
return View(cnty); // F11 jumps over this section of code returning me to the error page below.
}
return HttpNotFound();
}
再一次,我不知道它究竟在哪里或为什么出错。我怎样才能找出它抛出的原因或更好的错误是什么?
我正在使用 VS2012 mvc4 c#。
最佳答案
您需要在 View 本身中放置断点。您可以使用 razor 语法在任何内容上放置断点,例如:
@Html.ActionLink
@{ var x = model.x; }
如果您遇到空引用异常,请在 View 中使用模型的地方放置断点。
关于c# - 如何调试 mvc4 razor View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17281721/