Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# ASP.NET MVC Forms Improving Our Form Completing the β€œActivity” Field Drop Down List

"The name of ViewBag does not exist in the current context ... "

I keep getting the red underlines when hovering on ViewBag and Html Helper, the project run without any problems.

For the ViewBag, when I hover the mouse, it shows "The name of ViewBag does not exist in the current context ... "

For the @Html.DropDownListFor, it shows something like "Html helper does not contain the definition for ..."

Can someone help me to get rid of these?

Thank you

2 Answers

Steven Parker
Steven Parker
231,269 Points

I've seen the VS editor display false errors sometimes, but they go away once you've built the project (with no errors). Just a build will do, you don't have to run it.

Do you still see this after a successful build? Or are you using something other than VS?

They are still there after I built. I am using VS on Mac.

Steven Parker
Steven Parker
231,269 Points

It sounds like you may have discovered a bug in that version of VS. After a build is successful, the editor shouldn't be indicating errors.

I am not sure but this is web.config inside the Views folder. Can you help me what should I change here? I am not really familiar with these config files. The builds are always successful but still display errors.

<?xml version="1.0"?>

<configuration> <configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> </sectionGroup> </configSections>

<system.web.webPages.razor> <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> <add namespace="Treehouse.FitnessFrog" /> </namespaces> </pages> </system.web.webPages.razor>

<appSettings> <add key="webpages:Enabled" value="false" /> </appSettings>

<system.webServer> <handlers> <remove name="BlockViewHandler"/> <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /> </handlers> </system.webServer>

<system.web> <compilation> <assemblies> <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </assemblies> </compilation> </system.web> </configuration>

Steven Parker
Steven Parker
231,269 Points

The config file tunes the running environment. I don't know every possible parameter in it, but I really don't think it has any effect on the editor behavior or build environment.