Problems and Solutions of using Bundle in asp.net MVC4

Source: Internet
Author: User

Background
I have used MVC3 before, and I have also created the basic example of MVC4. I know that there is such a bundle method.

Recently I want to build a website to use MVC4, but I think it is not easy to change the basic example. There are too many useless things, so I created a blank MVC program, then write what you need,

The problem is that the target framework of the program is reduced from 4.5 to 4.0 (VS2013 is used.

Problems and Solutions
1. After the target framework is downgraded, vs reports a warning: the NuGet package is installed using a framework different from the current target framework. You need to update the System. web. http, used NuGet,

However, it is only used to add the required assembly. It has not been updated.

Solution: search for the answer. In the NuGet command window, use the Update-Package name for Update. For those who only use the NuGet Package management window, where is the command window?

Open the window and use the command update-package System. Web. Http to update.


2. When I saw Bundle for the first time, I thought it was convenient to write it when I referenced js or css in multiple places, now we know that it is more useful to merge and compress js or css files.

How can I use it? I don't know. I have a good solution. Let's create a basic mvc4 sample program.

Problem: First, you need to create a BundleConfig. cs class under the App_Star folder and define the RegisterBundles method. The BundleCollection object must be used as the parameter and no BundleCollection class is found.

Solution: Add a reference to System. Web. Optimization. dll to the program, and add using System. Web. Optimization to the class.

Problem: The BundleConfig. cs class has been written and registered in the Application_Start method of the Global. asax file. Use it in the View on the page, but there is no prompt when writing @ Styles. Render,

Why not? I didn't see any reference namespaces on the sample page?

Solution: the original namespace must be stored on the web. in config, there is a web under the program directory. config, which also has a web under the View folder. config, which is added to both files

<Add namespace = "System. Web. Optimization"/>. You can view web. config at the specific location.

Problem: OK. You have finished writing and running it. I will go and there is an exception. At first glance, the system prompts "when using relative paths, please make sure the current directory is correct". Is there a problem with the file path defined by BundleConfig. cs?

The problem is that WebGrease is not loaded.

Solution: Add reference program: antl3.runtime. dll and WebGrease. dll, add the following nodes to web. config under the program root directory

Question: When the program is running, no error is reported and everything is okay, but the Jquery. min. js file is not referenced?

Solution: As mentioned above, bundle has the File compression function. If the file name contains min, it will not be referenced. Therefore, remove min from the file name and change it to Jquery. js.

There is an article in the search process

New ScriptBundle ("~ The name in/bundles/js/jqueryContent ") cannot contain special characters .. For example,-otherwise it is invalid. Address

Summary: when using bunle, You need to reference three dll files and configure them in web. config. I don't know this if I don't start from 0.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.