微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp.net-mvc – App_Web _ * .dll中的System.NullReferenceException

我有一个奇怪的问题。

我的MVC应用程序似乎工作完美,除了一个视图页面

有问题的视图页面(组织/编辑)在页面上的每个代码项目上获得“NullReferenceException”。无论是Html.TextBoxFor()还是HTML.AntiForgeryToken()。

我有我的模型,视图和控制器在这里列出了我认为是相关的另一个问题 – http://stackoverflow.com/questions/26475866/dropdownlistfor-null-reference-error

如下所示,我的模型确实有信息。此屏幕捕获是在控制器内的“返回视图(”编辑“,型号)”中获取的。

异常详细信息

- 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,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()’。

所以似乎错误只发生在最后一个可能的代码区域。

解决方法

我找到了我的问题 here的答案

任何人找到这个:

尝试在错误后面注释下一个代码行。

@ModelType CheckImHereMVC.OrganizationEditviewmodel

@Using Html.BeginForm("Edit",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之后的行。这解决了我的问题。

链接:“有时编译器不能指出在剃刀视图中具有特定类型的错误的精确行可能是因为它不能将它们的行号保留在堆栈跟踪或某处,我发现这种情况与Null引用异常,当null为通过Url.Content。

因此,当您没有在堆栈跟踪中显示的行中没有得到任何错误时,可以检查razor视图中的下一个C#语句。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“WPF...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这...
Some samples are below for ASP.Net web form controls:(from http://www.visualize.uk.com/resources/asp
问题描述: 对于未定义为 System.String 的列,唯一有效的值是(引发异常)。 For columns not defined as System.String, the only vali
最近用到了CalendarExtender,结果不知道为什么发生了错位,如图在Google和百度上找了很久,中文的文章里面似乎只提到了如何本地化(就是显示中文的月份)以及怎么解决被下拉框挡住的问题,谈
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence changed a lot since 1.1. Here is the order: App
静态声明: &#39; Style=&quot;position: relative&quot; AppendDataBoundItems=&quot;True&quot;&gt; (无 或 空 或
以下内容是从网络上搜集资料,然后整理而来的。不当之处,请不吝指教。(The following were from network, and edited by myself. Thanks in a
Imports System Imports System.Reflection Namespace DotNetNuke &#39;*********************************
Ok so you have all seen them: “8 million tools for web development”, “5 gagillion tools that if you