My problem is very similar to this problem, except mine is in a sub-Area (right click, Create Area)
The name 'ViewBag' does not exist in the current context
I ran the upgrade tool and it did discover the web.config in the area, but I still get the error. My layout page is very simple:
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
</head>
<body>
<div>
@RenderBody()
</div>
</body>
</html>
And my content page looks like this near the top:
@model IEnumerable<ProjectName.Models.OrderViewModel>
@{
ViewBag.Title = "Index";
Layout = "~/Areas/Admin/_AdminLayoutPage.cshtml";
}
<h2>Index</h2>
The name 'ViewBag' does not exist in the current contextIt's probably a sign that you are running on an older version of ASP.NET MVC (or a pre-release of MVC 3). You can download the latest version of ASP.NET MVC 3 here.
Access Viewbag Value in External JavaScript file, It will throw an error ExternalJs. js:1 Uncaught SyntaxError: Invalid or unexpected token. So, create a JavaScript global variable and store the ViewBag and ViewData value in that global variable. Then, access that JavaScript variable in external JavaScript.
You should be aware that when creating an MVC application, you get two Web.Config
files. One in the root of the project and one under the Views folder. I had the same issue and for some reason when I was working on my project, I accidentally modified the one under the Views. Cleaning it (the one under the Views folder) fixed that error. Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With