MVC 4 @Scripts “does not exist”

后端 未结 24 1941
长发绾君心
长发绾君心 2020-12-12 11:20

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.

相关标签:
24条回答
  • 2020-12-12 12:03

    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 <add namespace="System.Web.Optimization"/> to both web.config files
    • Run Install-Package -IncludePrerelease Microsoft.AspNet.Web.Optimization
    • Update Bundling code
    • Update Layout file
    • The last step is to update 10 other libraries. I didn't and it worked fine. So looks like you can procrastinate this one (unless I already updated 1 or more of them). :)
    0 讨论(0)
  • 2020-12-12 12:04

    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.

    0 讨论(0)
  • 2020-12-12 12:04

    For me this solved the problem, in NuGet package manager console write following:

    update-package microsoft.aspnet.mvc -reinstall
    
    0 讨论(0)
  • 2020-12-12 12:05

    just remove/ hide the code from create & Edit razor view of your controller.

     @section Scripts {  
    
       @Scripts.Render("~/bundles/jqueryval")  
     }  
    
    0 讨论(0)
  • 2020-12-12 12:10

    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.

    0 讨论(0)
  • 2020-12-12 12:11

    Import System.Web.Optimization on top of your razor view as follows:

    @using System.Web.Optimization
    
    0 讨论(0)
提交回复
热议问题