开发者

Upgraded MVC3 project having problems with Razor Views

I upgrade a MVC 2 project to MVC 3. It is currently a small project and I only have one controller and a few views.

However, when I attempt to create a new view using Razor, I have ran into a number of issues:

1) Even though specifying a strong typed view, and it creates the

@model IEnumerable<AcmeProject.SomeObject>

I still get the error that Validation (XHTML 1.0 Traditional): Element 'AcmeProject.SomeObject' is not supported.

2) CS0103: The name 'ViewBag' does not exist in the current context

<head>
  <title>@ViewBag.Title</title>
</head>

This is a reference to the simple Layout view

3) (no longer an issue) originally, I was getting errors about the @model first line of the Razor view I am having issues with, and I had to add the following to the view/web.config file:

<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>

I am not sure how to resolve #1 and #2 and have been unsuccessful in trying a few solutions I came across in my search. However, I am also concerned I am going to continue having problems because it is an upgrade. As with computers, upgrading is the devi开发者_开发百科l's playground. Do I just need to create a new project and migrate my files over to it?


Make sure you have followed the steps outlined in the release notes about upgrading an ASP.NET MVC 2 project to ASP.NET MVC 3. There's also an ASP.NET MVC 3 upgrade tool you may try.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜