C# ASP.NET MVC Basics Modeling and Presenting Data Using Strongly Typed Views

Ellis Garaudy
PRO
Ellis Garaudy
Pro Student 9,705 Points

Object reference not set to an instance of an Object. Line 5: ViewBag.Title = Model.DisplayText;

Hi getting an error in post-build with the page title.

Details.cshtml ViewBag.Title = Model.DisplayText;

ComicBook.cs public string DisplayText { get { return SeriesTitle + " #" + IssueNumber; } }

Steven Parker
Steven Parker
200,417 Points

I'd need to see more of the code to determine what's causing the error. Clearly, either "ViewBag" or "Model" is null at line 5, but the reason for it cannot be seen here.

1 Answer

James Churchill
STAFF
James Churchill
Treehouse Teacher

Ellis,

As Steven mentioned, it's difficult to know what is the cause of the error without having more context. That being said, I would double check if the controller action method (that's associated with this view) is passing a data model object instance to the View method call.

Thanks ~James