5

As a learning exercise, I've created a blank MVC4 Application and I'm building a blog-type website with it.

I'm learning that this probably wasn't the best idea... I've copied the Content and Views\Shared folders into my blog project from another one I created with the default stuff, but the following lines are giving me errors:

@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")

Both underlined red in my _Layout.cshtml file, the error is:

The name does not exist in the current context

So I went back to my "default" project and checked where those come from by hovering over them. The tooltip said

class System.Web.Optimization.Styles
class System.Web.Optimization.Scripts

So I went through and installed the Web Optimization Framework as per this question but it hasn't fixed the problem.

The project builds n all, but no styles are applied and I'm 100% sure anything that the script controls isn't working either...

Can anyone help me fix this?

Community
  • 1
  • 1
Ortund
  • 8,095
  • 18
  • 71
  • 139
  • 1
    Make sure you've defined those bundles in BundleConfig.cs file like bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css")); – malkam May 15 '14 at 18:27
  • 5
    Make sure you include `` in your Views folder `web.config` file as well. Might need to close and open your solution again for Visual Studio's intellisense to pick it up though. – dom May 15 '14 at 18:29
  • @malkam thanks! Had to change the namespace there for it to work, but I also had to reload the solution as `Dom` suggested – Ortund May 15 '14 at 18:35
  • @malkam I got that sorted as per my last comment, but now the is being rendered as `` ... I've checked it against an unmodified "Internet Application" template and everything I can see looks exactly the same – Ortund May 15 '14 at 19:12
  • Turns out I needed to register the Bundle in the Global.asax file – Ortund May 15 '14 at 19:41

1 Answers1

2

add <add namespace="System.Web.Optimization" /> tag into your web.config that is inside of Views folder

like this :

>  <system.web.webPages.razor>
>     <host factoryType= ... />
>     <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" />
>         <add namespace="System.Web.Optimization" /> 
>       </namespaces>
>     </pages>   
>  </system.web.webPages.razor>