I have just created an ASP.NET MVC 4 project and used Visual Studio 2012 RC to create a Controller and Razor Views for Index
and Create
Actions.
I had the same problem and I used WinMerge to help me track this down. But as I researched it more, I found that Rick has the perfect blog post for it.
Summary:
<add namespace="System.Web.Optimization"/>
to both web.config filesInstall-Package -IncludePrerelease Microsoft.AspNet.Web.Optimization
There was one small step missing from the above, which I found on another post. After adding
<add namespace="System.Web.Optimization" />
to your ~/Views/web.config
namespaces, close and re-open Visual Studio. This is what I had to do to get this working.
For me this solved the problem, in NuGet package manager console write following:
update-package microsoft.aspnet.mvc -reinstall
just remove/ hide the code from create & Edit razor view of your controller.
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
I upgraded from Beta to RC and faced 'Scripts' does not exist issue. Surfed all over the web and the final solution is what N40JPJ said plus another workaroudn:
Copy the following in View\Web.config :
<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"/>
<add namespace="System.Web.Helpers"/>
</namespaces>
and the following inside View\Shared_Layout.cshtml
@if (IsSectionDefined("scripts"))
{
@RenderSection("scripts", required: false)
}
Hope it helps.
Import System.Web.Optimization on top of your razor view as follows:
@using System.Web.Optimization