简体   繁体   中英

How to use an existing MasterPage from a WebForms project inside an MVC Area?

I am attempting to use an existing MasterPage from a WebForms project and use it with an MVC area added to the same solution.

I've read this blog and I am currently stuck on how to connect the two. I've added the extension methods and all of the items he suggests in the Shared folder.

In his example the Shared/RazorView.aspx file I get two errors on this line.

<% Html.RenderPartial((string) ViewBag._ViewName); %>

`The name 'Html' does not exist in the current context`
`The name 'ViewBag' does not exist in the current context`

How do you reference the MasterPage, or setup the views so you can use the MasterPage as partial content?

You're almost there. You just need to configure ASP.NET WebForms to know what MVC is in the Views/web.config :

<system.web>
  <pages pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
          pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
          userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <controls>
      <add assembly="System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
    </controls>
    <namespaces>
      <add namespace="System.Web.Mvc.Html"/>
    </namespaces>
  </pages>
</system.web>

In order to get the RenderPartial extension method to work, you also need to add the namespace System.Web.Mvc.Html .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM