How can I use an existing MasterPage from a WebForms project inside an MVC scope?
I am trying to use an existing MasterPage from a WebForms project and use it with an MVC scope added to the same solution.
I was reading this blog and I am currently stuck on how to pair the two. I added extension methods and all the items it offers in the folder Shared
.
In his example file, Shared/RazorView.aspx
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 link to MasterPage or customize views so you can use MasterPage as partial content?
source to share
You're almost there. You just need to configure ASP.NET WebForms to find out what MVC is in 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>
To get an extension method RenderPartial
, you also need to add a namespace System.Web.Mvc.Html
.
source to share