Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Styles and Scripts do not exist in the current context

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?

like image 891
Ortund Avatar asked Oct 31 '22 23:10

Ortund


1 Answers

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>
like image 187
Sayid Yarmohammadi Avatar answered Nov 15 '22 05:11

Sayid Yarmohammadi