web-dev-qa-db-ja.com

App_Web _ *。dllのSystem.NullReferenceException

私は奇妙な問題を抱えています。

1つのビューページを除き、MVCアプリケーションは完全に正常に動作しているようです。

問題のビューページ(組織/編集)は、ページ上のすべてのコード項目で 'NullReferenceException'を取得します。 Html.TextBoxFor()またはHTML.AntiForgeryToken()

私が関連していると思う別の質問について、ここに私のモデル、ビュー、コントローラーをレイアウトしました- https://stackoverflow.com/questions/26475866/dropdownlistfor-null-reference-error

以下に示すように、mymodelには内部情報があります。この画面キャプチャは、コントローラー内部の「Return View( "Edit"、model)」で取得されました。

例外の詳細

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

enter image description here

表示

@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

私が気づいたことの1つは、「textboxfor」をコメントアウトすると、「ValidationSummary()」でエラーが発生し、「ValidationSummary()」でコメントアウトすると、「AntiForgeryToken()」でエラーが発生することです。

そのため、エラーは最後の可能なコード領域でのみ発生するようです。

25
MaylorTaylor

私の問題に対する答えを見つけました ここ

これを見つけた人には:

エラーの後、次のコード行をコメントアウトしてみてください。

@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の行[〜#〜] after [〜#〜]をコメントアウトしました。これで問題が解決しました。

リンクから:「かみそりビューで特定の種類のエラーが発生した正確な行をコンパイラーがポイントできない場合があります。スタックトレースまたはどこかに行番号を保持できなかったためです。 Url.Contentで渡されます。

そのため、スタックトレースで表示される行でエラーが発生しなかったときに、カミソリビューで次のC#ステートメントを確認すると役立ちます。」

37
MaylorTaylor