Original article address: jquery Ajax with Asp.net MVC preview 5
Original Author: Chris Van de Steeg
Recently I spent a little time updating my jquery4mvc project to preview 5 to adapt to some changes from MVC P4 to MVC P5. Read this article. Read the new features of preview 5 introduced by Scott's post. He will also release the ajaxhelpersArticle. If you want to skip reading and directly download jquery4mvc: Click codeplex.
The jquery4mvc JavaScript package contains only three JavaScript files and allows the use of Microsoft's default ajaxhelper. You only need to copy these three files to your content directory and reference them in the head section to replace microsoftajax. js and microsoftmvcajax. js. Jquery can perfectly replace microsoftajax to complete all Ajax functions. The exciting thing is that it will support the forward and backward buttons for your Ajax link.
In this way, we can continue to use the ajaxhelper function as before. Although ajaxhelpers has some changes in preview 5, if you haven't updated ajaxhelper, you can still use Scott hanselman's article ASP. net MVC preview 4-using Ajax and Ajax. to understand it. Note that in preview 5, you cannot use inline Javascript in ajaxoptions. Now you must specify the method name. You can also download the entire jquerymvc Project, which contains a website example to demonstrate the features of jquerymvc.
We will discuss more about the. js file in the project! The purpose of this project is to create an Ajax application based on MVC.ProgramIt can be implemented and run faster. We use a unified default IOC container.
I want to accurately describe what this project is for you. The best way is to browse the sample Website.CodeHere is a brief introduction. First, we have a defaultview engine. If you use the [defaultview] attribute to mark your controller, as follows:
If you open the example/home/index, the index view will be searched by default. If no view is found, the defaultview engine searches for the specified view name (such as default in the example ). It doesn't matter what view engine your view uses. It will work for all views. Can this be done? Let's take a look at the view directory structure in the example.
As you can see, most views only have one ascx file prefixed by the following line. Because when action home/about, home/sayhello, home/index is called, these views will not be retrieved, and the defaultview view engine will open shared/default. aspx.
As you can see, it only calls masterpage. You can create different default pages for each controller. Like masterpage, the following code:
This special contentplaceholder works like a normal placeholder. However, it does not obtain new content from the page. It calls the view engine to open the view with corresponding underscores on the action. Therefore, if you call home/about, it will call home/_ about. Amazing, right? For other pages, you only need to create an ascx file (or for other parts, if you use another view engine ). This part of the view will be filled into the home page.
Wait, there are more! If you use an Ajax request to access the controller using the [ajaxcontroller] attribute, it will only return the. ascx view. It's so good! Very similar to updatepanel!
Go to codeplex and download the project to see the Ajax-magic I'm so excited about!
Source codeYou can also go to Google Code download: http://code.google.com/p/jquerymvc/source/checkout
Online Demo of sample Website: http://www.chrisvandesteeg.nl/demo/jquerymvc5/