3

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.