1

Thanks for reading this.

In the _Layout.cshtml page I use the @RenderPage to call the header:

@RenderPage("/Shared/_header.cshtml")

It has this:

<div id="Header"> Home </div>

Want to make it clickable to the default action ("Index")

When I tried this:

<div id="Header"> @Html.Action("Index", "MyController") </div>

The 'Action' is underlined in red with this error:

'System.Web.WebPages.Html.HtmlHelper' does not contain a defintion for 'Action' and no extension ......

"System.Web.Mvc" is referenced in the project as well in the config file:

<add namespace="System.Web.Mvc" />

Any ideas?

scv
  • 323
  • 10
  • 20

2 Answers2

9

You need to copy Views/Web.config to /Shared.

This will tell Razor to use the MVC base type & parser

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • Thanks; I know I can move the _header and footer to /view/shared it's that ok? BTW, thanks for your blog. – scv Jun 08 '12 at 20:56
  • Yes; that would be better. Typically, though, you should put the header directly in the layout, not in a separate file. – SLaks Jun 08 '12 at 20:59
  • Also, call `Html.Partial` (MVC version), not `RenderPage()` (WebPages version) – SLaks Jun 08 '12 at 20:59
  • You mean something like this: [link] (http://stackoverflow.com/questions/10552502/passing-data-to-a-layout-page) – scv Jun 08 '12 at 21:08
  • If you need to pass data, call the child action directly from the layout. – SLaks Jun 08 '12 at 21:18
0

I've moved from mvc4 to mvc5
All I needed to do is change this key value at web.config from 2

 <add key="webpages:Version" value="3.0.0.0" />
Haddar Macdasi
  • 3,477
  • 8
  • 37
  • 59