Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC3/Razor: cshtml.Execute()': no suitable method found to override

I am trying to convert an MVC2 site to MVC3 using RazorViewEngine.

I used this tool to upgrade my project and the Telerik converter tool to convert my .aspx views to Razor. The Telerik tool put an @inherits line at the top of my layouts (inherting from ViewMasterPage).

When I tried to run a page that used one of these layouts, I got the error:

...cshtml.Execute(): no suitable method found to override

I removed the @inherits tag and it started to work for my home page. However, I continued to get this error for another page using the same layout. And now, after moving some things around to deal with an Areas issue, I'm back to getting this error for all my pages (the ones I can get to, anyway).

I have tried closing Visual Studio, deleting temporary files, etc.

like image 382
sydneyos Avatar asked Jan 26 '11 18:01

sydneyos


2 Answers

Figured it out - the following section needs to be in the web.config for razor - I had it in the web.configs in the Views directories, but not in the root web.config:

 <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>
like image 72
sydneyos Avatar answered Oct 12 '22 12:10

sydneyos


There could be a few things going on here. Make sure you are following these guidelines

  • you don't have @inherits directives in your views. unless you are using a custom view page base class they are unnecessary. For strongly-typed views you should use the @model directive to specify the model type. For weekly-typed views you don't need anything.
  • don't mix razor views with aspx master pages (or aspx pages with razor layouts), as they don't work together easily. This includes checking all of your action methods where you have code like return View("ViewName", "MasterName") since that might also cause conflicting templatign technologies to be used.
like image 32
marcind Avatar answered Oct 12 '22 10:10

marcind