Monday, April 27, 2015

How to fix "CS0103: The name 'Scripts' or 'Content' does not exist in the current context" Error in MVC Share Assembly

when i try to integrate a MVC share assembly(which is running under Web Razor View Engine) into a MVC web project which runing with WebForm view engine.

i go the following error message :Compiler Error Message: CS0103: The name 'Styles' does not exist in the current context




the solution is to follow the steps.

1. add  <add namespace="System.Web.Optimization" /> to the web.config file under the Views folder in the MVC Share Assembly project.

2. install "Mincrosoft Asp.net Web Optimization Framework" package via the Manage NuGet Package Window to the MVC share assembly project.



 3. added Bundle Configuration Logic to Global.asax in the MVC WebForm Project

 protected void Application_Start()
        {
            MvcRazor.SetupMvcRazor.Setup();

            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
            RegisterBundles(BundleTable.Bundles);
        }

        protected void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate*"));

            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/respond.js"));

            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css"));
        }

then you will see MVC share assembly page from the MVC Web Form Application.










No comments:

Post a Comment