Using ASP.net MVC4 in bundle problems and solutions sharing _ practical Tips

Source: Internet
Author: User

background
Have previously used MVC3 experience, also built MVC4 basic sample to see, know that there are bundle such a method.

Recently want to build a website to use MVC4, but I think in the basic sample to change bad, there are too many useless things, so I built a blank MVC program, and then write their own things,

The problem is that the target frame of the program is reduced from 4.5 to 4.0 (I'm using VS2013).

Problems and Solutions
1. After lowering the target framework, VS reported a warning: The NuGet package is installed using a target framework different from the current target framework, and needs to be updated System.Web.Http, previously useful nuget,

But just use it to add the required assembly, not updated AH.

Solution: Search, not difficult to find the answer, in the NuGet command window, using the Update-package package name to update, for those who use only the Management NuGet package window, where is the command window?

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


2, the first time to see the use of bundle time, feel that there are many references to JS or CSS when the time to write on the convenience, now know that it is more useful for JS or CSS file merge compression.

Specific how to use it, do not know, to solve, and then a separate new MVC4 basic sample program to see.

Problem: First you need to create a new BundleConfig.cs class under the App_star folder, define the Registerbundles method, need Bundlecollection object as a parameter, find no Bundlecollection class

Resolve: The program adds a reference to System.Web.Optimization.dll, and a using System.Web.Optimization is added to the class

Question: BundleConfig.cs class is written, in the Global.asax file Application_Start method registered, that in the page view use it, but write @styles.render how do not give a hint,

Why not? Don't you see a reference namespace on the sample page?

Workaround: Originally this namespace needs to be added in Web.config, there is a Web.config in the program directory, there is a Web.config under the View folder, in two files are added

<add namespace= "System.Web.Optimization"/>, the specific location you see Web.config will know.

Question: OK, all written to run it, I go, out of the abnormal. The first thing you see is the hint "when using relative paths, make sure the current directory is correct", is it a problem with the BundleConfig.cs-defined file path?

The problem is not loading webgrease

Resolve : Program Add Reference: Antlr3.Runtime.dll and WebGrease.dll, add the following node to Web.config in the program root directory

Question: The program runs up, no error, thought all OK, but found Jquery.min.js file no reference on?

Solve: The above mentioned bundle has the function of compressing files, the file name has min it does not quote, so the name of the Min removed, changed to jquery.js on it.

There's an article in the search process that says

The name in the new Scriptbundle ("~/bundles/js/jquerycontent") cannot have a special symbol. Like what. -otherwise not valid. Address

Summary: In the use of Bunle process need to refer to three DLLs, in the web.config to do two configurations, I think if I do not start from 0, I will not know these.

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.