开发者

Upgraded to MVC 3: CS0103: The name 'View' does not exist in the current context

I have just updated to ASP.NET MVC 3 RC2.

The sample app I am working on now produces the followin开发者_Python百科g error, whenever a cshtml view is rendered:

CS0103: The name 'View' does not exist in the current context

It fails on the line:

@{
   View.Title = "MyView";
}

... and fails anywhere else it encounters View in the code on the Razor file.

I have copied the web.config from a new apps View folder to my sample app, but the problem persists.

A brand new application runs without problems.

I have also rebuilt the solution, run Clean Solution. No joy.

I haven't worked on the sample for a few days. So it might be an issue that has nothing to do with RC2...


It's been renamed 'ViewBag'. You can read more about the changes from RC1 -> RC2 here


I had the same problem, but I just tried to guess what to use now, I ended up using:

@Page.Title = "The title"

and it worked, though I'm not sure what is the "best practice" now

Also, I thought that the ViewBag is what used to be ViewModel, not just View


I'm adding this in case anyone else comes across it. Another possible cause is that your Layout was not found. I deployed to IIS and (after commenting out the offending line) found that the Layout hadn't been copied during web deploy. In my case, it was because the layout's Build Action had been changed from Content to None.

EDIT: In fact, I had MVC 3 RC installed. The above was just a different symptom. The deployment machine had RTM which exposed the problem. As awrigley says, it's called ViewBag now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜