I’m having an excessively strange issue.
I’m working on a project and it’s being converted to use asp.net MVC.
Everything works the controllers/models/views. I get every keyword possible in the controller (ViewBag, ViewContext, etc.).
In my views, however, I only get some helpers (e.g. @Model, @Html), but I’m missing others (@model, @ViewBag, @ViewContext, etc.)
It’s an enormous hinderance (i’d post code but I don’t know what code is really relevant). My web.config is 100% dead-on and all of my other MVC projects do not have this issue.
- Web.Config is correct(in the Views folder)
- Target framework is correct
- I have access to all of the methods in my controllers
I’ve cleaned the project/re-mapped it, etc. Others on other machines do not have this issue, but oddly I do (I’ve entirely re-checked out the project).
Like I said, i don’t know what code is relevant I’m just hoping someone else has an idea as what can be wrong. I’m baffled since the web.config is right, i’m not missing any references (all my references are pointing to the correct location), and I can use all of them in the controller.
Just because I don’t want to get yelled at, here’s an excerpt from my web.config in the Views/ folder
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.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=3.0.0.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" />
</namespaces>
</pages>
</system.web.webPages.razor>
One of the strangest issues i’ve ever experienced :O
Sample:
@model Project.WebUI.Models.MyModel
@{
ViewBag.title = "hi";
}
<div>@Model.someItemInTheModel</div>
model is red underlined ‘does not exist in current context’
@model Project.WebUI.Models.MyModel
ViewBag is red underlined ‘does not exist in current context’
ViewBag.title = "hi";
This line is perfectly fine
<div>@Model.someItemInTheModel</div>
Controller, this is all perfectly fine
public ActionResult MyView(long date)
{
MyModel model = new MyModel();
model.someItemInTheModel = "hi";
return PartialView(model);
}
Create a new MVC3 project and compare those web.config files to the ones in your project. You’ll need the check the in the project root (
/web.config) and in/Views/web.config.Also check to make sure you have all of the same
System.Web.*references.