如何调试mvc4剃须刀看法? [英] How can I debug mvc4 razor views?

查看:127
本文介绍了如何调试mvc4剃须刀看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经习惯了C#和vb.net的WinForms,通常能找到我所需要的所有错误,只需设置一个断点,并通过我的code步进。

I'm used to C# and vb.net winforms, and usually can find all the errors I need just by setting a breakpoint and stepping through my code.

我想知道我做错了。

我在这里放置一个断点:

I'm placing a breakpoint here:

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();
}

再一次我不知道在哪里,为什么它究竟是出错了。我怎样才能找出原因或者更好的是什么错误时被抛出?

Yet again I have no clue where or why it errored out exactly. How can I find out why or better yet what error it is throwing?

我使用VS2012 mvc4 C#。

I'm using VS2012 mvc4 c#.

推荐答案

您需要把断点在视图本身。您可以使用剃刀语法断点放置任何东西,如:

You need to put breakpoints in your view itself. You can place breakpoints on anything using razor syntax such as:

@Html.ActionLink
@{ var x = model.x; }

如果你得到一个空引用异常,把你在哪里消费模式在您的视图的地方断点。

If you are getting a null reference exception, put breakpoints on places where you consume the model in your view.

这篇关于如何调试mvc4剃须刀看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆