JQuery is an easy-to-use JavaScript library that can be used by any Web development platform. It is particularly eye-catching in combination with the ASP. net mvc framework. James Estes once published an article on InfoQ titled jQuery, Which is winning the hearts of the people by version 1.2 and jQuery UI. He talked about the latest release of jQuery and introduced many outstanding features.
With the built-in scalability of ASP. net mvc, developers can use third-party libraries, such as jQuery. When using ASP. NET Webforms, it is difficult to use jQuery instead of ASP. net ajax.
At the beginning of this article, ASP. net mvc version is Preview 4, and some technologies used in Preview 4 may not work properly in earlier versions. Preview 4 can be downloaded on CodePlex.
Initial Configuration
I don't plan to write it into a complete jQuery guide, just a few examples of using this JavaScript library with ASP. NET MVC. Chad Myers has a wonderful guide, including how to get started.
First, you must ensure that you have ASP. net mvc, So download and install it from CodePlex (Note: You must run Visual Studio 2008 to use the ASP. net mvc Framework ).
After the ASP. net mvc framework is installed, a new ASP. net mvc Web Application project has been created.
Next, download jQuery, download Packed or Minified, and put it in the Content directory of the project above.
Add a reference to the jQuery file in the Content directory.
Simple Example
Ryan Lanciaux wrote an excellent article titled jQuery and ASP. net mvc frameworks, listing many key factors for using jQuery in the ASP. net mvc framework. Ryan elaborated in the article:
First, create an ASP. net mvc (Preview 4) project, create a new view and a controller action under the Home controller, and then add the following lines to the view.
This is red text, this is blueand this is green
Right-click the Controllers folder, select "Add New Item", and select the MVC Controller class. The task is completed. The next step is to create a Controller Action:
Next, we need to create a Controller Action, which can return the pigment value from the Model. In addition, we do not want to overload pages, but we want to use Ajax. Fortunately, we can use the JsonResult type in the MVC Framework to accomplish this.
Public JsonResult RGBColors () { Colors. RGB color = new Colors. RGB (); Return Json (color );} |
Next, create a class to indicate the color in the model:
- 2 pages in total:
- Previous Page
- 1
- 2
- Next Page