CS0103: The name ‘ViewBag’ does not exist in the current context _viewstart

You might get the above error if you try to access @ViewBag from within _ViewStart.cshtml. One solution is use _Layout.cshtml and point your _ViewStart.cshtml to the layout page. Everything should work fine.

// _ViewStart.cshtml page
@{
    Layout = "~/Views/_BasicLayout.cshtml"; <--- link to Layout Page
}
This entry was posted in Software Development. Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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