asp.net-mvc – App_Web _ * .dll中的System.NullReferenceExcep
我有一个奇怪的问题。
我的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: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,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#语句。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- TeamCity – 在ASP.net网站上发布的问题
- asp.net-mvc – 使用实体框架的没有存储库模式的依赖注入
- api – 通过msxml2.ServerXMLHTTP提供身份验证信息
- asp.net – 使用CRC的较短GUID
- asp.net – Azure WebJob超时配置设置
- asp.net-mvc – Elmah.MVC在IIS Express下工作但不是IIS 7.
- asp.net – 在哪里可以下载DLR的Managed JScript?
- asp.net – 如何打包/发布PDF以进行部署?
- 使用可靠的WPF / .NET背景学习ASP.NET MVC
- asp.net – FormsAuthentication:是否安全?