App_Web_*.dll 中的 System.NullReferenceException [英] System.NullReferenceException in App_Web_*.dll

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

问题描述

我遇到了一个奇怪的问题.

除了一个视图页面外,我的 MVC 应用程序似乎工作得很好.

有问题的视图页面(组织/编辑)在页面上的每个代码项上都得到一个NullReferenceException".无论是Html.TextBoxFor()还是HTML.AntiForgeryToken().

我在另一个我认为相关的问题上列出了我的模型、视图和控制器 --

对于发现此内容的任何人:

尝试在错误后注释掉下一行代码.

@ModelType CheckImHereMVC.OrganizationEditViewModel@Using Html.BeginForm("Edit", "Organization", FormMethod.Post)@Html.AntiForgeryToken()@Html.ValidationSummary(真)@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="图像"/>'注释掉这一行解决了我的问题结束使用

在上述情况下,我会在 model.organizationSub.subTitle 上出现错误.如果我注释掉那行,我会在 model.organizationSub.subName 行上得到错误.然后我找到了提到的链接并注释掉了我所有 TextBoxFors 的 AFTER 行.这解决了我的问题.

来自链接:有时编译器无法指出在剃刀视图中具有特定类型错误的确切行可能是因为它无法将它们的行号保留在堆栈跟踪或某处.我发现这种情况下存在空引用异常和在 Url.Content 中传递 null 时.

因此,当您在堆栈跟踪显示的行上没有收到任何错误时,检查 razor 视图中的下一个 C# 语句会很有帮助."

I am having an odd issue.

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

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().

I have my model, view, and controller laid out here on another question that i think is related -- https://stackoverflow.com/questions/26475866/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.

Exception Details

- Source = App_Web_zu4jlld0
- StackTrace =    at ASP._Page_Views_Organization_Edit_vbhtml.Execute() in C:UsersmtaylorProjectsCheck Im Heremtaylor-branchCheckImHere_v2CheckImHereMVCViewsOrganizationEdit.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)

View

@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

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()'.

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

解决方案

I found the answer to my problem here

For anyone finding this:

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

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.

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.

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."

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

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