ViewBag.Title “Object Reference Not Set”

It can be puzzling when you see something like the following getting a NullReferenceException, with “Object reference not set to an instance of an object.”

   1: @{

   2:     ViewBag.Title = "Report";

   3: }

The actual offending line of code is actually somewhere else in the view.  You probably need to try to go through a process of elimination by comment out section of the view code.

It is my case, the cause is the next time when I tried to assign to one of the properties of the model. The property was null, thus the error.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s