So I am upgrading a project from webforms to mvc 5 and I got the solution to run with both technologies.

The solution have many different projects. One where the Controllers and Models exists. One with a custom MVC implementation (viewengine, controllerfactory, routing) and one with the razorviews.

The poblem is that VS15 do not recognize some razor syntax. ViewBag is fine and @model ClassName works. BeginForm() works without parameters. To clearify, VS15 accepts this as valid syntax:

@model User
@{ 
  ViewBag.Title = "Test";
}

@using(Html.BeginForm())
{
  @Html.Editor(Model.Name)
}

And this as not valid:

@using(Html.BeginForm("test", "mvc", FormMethod.Post))
{
  @Html.EditorFor(model => model.Name)
}

For Html.BeginForm:

Reference to type 'RouteValueDictionary' claims it is defined in 'System.Web', but it could not be found.

And for Html.EditorFor:

Reference to type 'Func<,>' claims it is defined in 'mscorlib', but it could not be found.

The lamdba:

Feature 'lambda expression' is not available in c# 2. Please use language version 3 or greater.

The project uses C# 6.

The code is valid when I run the application.

The webconfig have these configurations:

<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" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <system.web>
    <compilation targetFramework="4.6">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </assemblies>
    </compilation>
  </system.web>

Related posts

Recent Viewed