System.NullReferenceException在App_Web _ *。dll的 [英] System.NullReferenceException in App_Web_*.dll

查看:1418
本文介绍了System.NullReferenceException在App_Web _ *。dll的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题。

我的MVC应用程序似乎是工作,除了一个视图页面完全正常的。

My MVC application seems to be working perfectly fine except for one view page.

在考虑中的视图页面(组织/编辑)获取页面上的每个code项的NullReferenceException。无论是的 Html.TextBoxFor() HTML.AntiForgeryToken()

The view page in question (Organization/Edit) gets a 'NullReferenceException' on every code item on the page. Whether it is Html.TextBoxFor() or HTML.AntiForgeryToken().

我有我的模型,视图和控制器奠定了这里的另一个问题,我认为是相关的 - <一个href=\"http://stackoverflow.com/questions/26475866/dropdownlistfor-null-reference-error\">DropDownListFor空引用错误

I have my model, view, and controller laid out here on another question that i think is related -- DropDownListFor null reference error

正如你可以看到下面,我的模式确实有它的内部信息。此屏幕捕获摄于返回查看(编辑,模型)控制器内部。

As you can see below, my model does have information inside of it. This screen capture was taken at the "Return View("Edit", model)" inside the controller.

异常详细信息

- Source = App_Web_zu4jlld0
- StackTrace =    at ASP._Page_Views_Organization_Edit_vbhtml.Execute() in C:\Users\mtaylor\Projects\Check Im Here\mtaylor-branch\CheckImHere_v2\CheckImHereMVC\Views\Organization\Edit.vbhtml:line 16
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.StartPage.RunPage()
   at System.Web.WebPages.StartPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)

查看

@ModelType CheckImHereMVC.OrganizationEditViewModel

@Using Html.BeginForm("Edit", "Organization", FormMethod.Post)
 @Html.AntiForgeryToken() 'get errors here
 @Html.ValidationSummary(True) 'get errors here
 @Html.TextBoxFor(Function(model) model.organizationSub.subName, New With {.class = "span12"}) 'and errors here
End Using

有一件事我注意到的是,如果我注释掉我的'textboxfor,将发生在'的ValidationSummary()我的错误,如果我注释掉我'的ValidationSummary()',那么将出现在AntiForgeryToken我的错误( )。

One thing i notice is that if i comment out my 'textboxfor', my error will occur at the 'ValidationSummary()', if i comment out my 'ValidationSummary()', then my error will occur at 'AntiForgeryToken()'.

如此看来,错误恰好在最后可能code区。

So it seems that the error just happens at the last possible code area.

推荐答案

我找到了答案,我的问题<一href=\"http://stackoverflow.com/questions/22412391/mvc5-razor-nullreferenceexception-in-model\">here

I found the answer to my problem here

对于任何人找到这个:

尝试注释掉下一个code线的错误之后。

Try commenting out the next code line AFTER the error.

@ModelType CheckImHereMVC.OrganizationEditViewModel

@Using Html.BeginForm("Edit", "Organization", FormMethod.Post)
   @Html.AntiForgeryToken() 
   @Html.ValidationSummary(True) 
   @Html.TextBoxFor(Function(model) model.organizationSub.subName, New With {.class = "span12"})
   @Html.TextBoxFor(Function(model) model.organizationSub.subTitle, New With {.class = "span12"})
   <img src="@Url.Content(Model.img.imgPath)" alt="IMAGES"/> 'commenting out this line fixed my issue
End Using

在上面的例子中,我会得到的 model.organizationSub.subTitle 错误。如果我评论说出来行,我会得到的 model.organizationSub.subName 线路故障。后来我发现链接提及,注释掉行我所有的TextBoxFors的。该固定我的问题。

In the case above, i would get errors on the model.organizationSub.subTitle. If i commented that line out, i would get errors on the model.organizationSub.subName line. I then found the link mentioned and commented out the line AFTER all of my TextBoxFors. That fixed my issue.

从链接:有些时候编译器不能在具有特定类型的剃须刀观点的错误可能是因为它不能保持堆栈跟踪或其他地方的行号确切行的观点,我发现这种情况下,与空引用异常和空时传入Url.Content。

From link: "Some times compiler could not point on exact lines having specific kind of errors in razor view may be because it could not keep their line number in stack trace or somewhere. I have found this case with Null Reference Exception and when null is passed in Url.Content.

所以它有助于检查剃刀查看下一个C#语句时,你没有得到通过堆栈跟踪显示线路上的任何错误。

So it helps to check the next C# statement in razor view when you did not get any error on the line shown by stack trace."

这篇关于System.NullReferenceException在App_Web _ *。dll的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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