Answer the question
In order to leave comments, you need to log in
ASP.NET MVC: how to determine where in a Razor view an exception occurs?
Hello.
An Exception occurs in the view code on the server. locally displays an error like this:
[NullReferenceException: Object reference does not point to an instance of an object.]
ASP._Page_Views_Purchase_Rows_cshtml.Execute() +83733
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +279
System.Web.Mvc.WebViewPage.ExecutePageHierarchy () +124
System.Web.WebPages.StartPage.ExecutePageHierarchy() +142
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +180
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context ) +379
System.Web.Mvc.<>c__DisplayClass1a.b__17() +32
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +613
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +613
System.Web. Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +263
System.Web.Mvc.Async.<>c__DisplayClass25.b__22(IAsyncResult asyncResult) +240
System.Web.Mvc.<>c__DisplayClass1d.b__18( IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15
System.Web.Mvc.<>c__DisplayClass8.b__3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass4.b__3( IAsyncResult ar) +15
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
Is it possible to determine in which location (line of code), or at least what operation is causing this error? and if so, what is it?
So far, I'm taking the approach of pasting in different parts of the try catch block code, rebuilding the solution, uploading it to the server, restarting the server, and checking if the error is gone...
Answer the question
In order to leave comments, you need to log in
This is some kind of problem in your view.
ExecuteResult - means the controller passed, and we fall when the view is rendered.
look in the ViewBag for what the missing link goes to.
Often, when there is a problem in the Razor view, the error is shown not at all on the line where it actually exists. Therefore, I usually start commenting on suspicious pieces on the sly until I find the source of the error.
Check the data received from the database for null
https://forums.asp.net/t/1899637.aspx?I+have+a+ver
... -...
If the problem is only on the external one, then delete the project and upload it again, maybe some tails from old assemblies.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question