The videos above will show us how to use MVC to build websites. Afterfinishing the videos, we can get the basic principle from the link below if we want:
2
How to realize a grid view with ASP.NET MVC ?[Top]
The question how to implement the GridView with ASP.NET MVC is often asked on the ASP.NET MVC forums. There are many answers and we pick some popular ones as a FAQ for your reference.
The sample is quite simple and easy to use; first let us check this code below about the definition of ‘PaginatedList’ class.
And now, let us check this code below; the code is used for getting data from database and converting the data to the ‘PaginatedList’,
Here is the view code below; it is generated by the Microsoft Visual Studio 2008(IDE), now we need to change the following code:
To:
If we do not want to change this, we need to implement the IEnumerable interface for PaginatedList by changing the followingcode:
To:
Also we need to assign a route for getting paginated data; here we assign the “News” for this demo code:
And now let’s check the last part, the “News” route; it’s also quite simple.
3What is difference between ViewData and TempData? [Top]
TempData is used for passing data from one request to other request.
ViewData is used to pass data from controller to view.
Please check this code below,
Here is the T2 view code below:
After test, we cannot see message of “This is ViewData in the action T!” on the T2 view (page).
If you want to know the basic principle, please check these articles,
4How to choose between ASP.NET Web Forms and MVC? [Top]
The illustration below is enumerating difference between “ASP.NET Web Forms” and “ASP.NET MVC”. It is very helpful for deciding whether to use ASP.NET Web Forms or ASP.NET MVC,
Web Forms
ASP.NET MVC
Tooling/designer
Postbacks
Event driven
HTML forms and viewstate
Controls abstraction
3rd party component model
Rapid development
Declarative syntax
Full control over markup
Lightweight views/no Codebehind
Separation of concerns
Testing/TDD
Pluggable view engines
RESTful
No postbacks
No viewstate
If you are interested in mixing the Web Forms and the MVC, you can check the following website on How do I mix Web Forms and MVC .
For convenience, we take the calendar (datepicker) as example.
Before we do this, we need to download two JavaScript files from the jQuery website, one is called “jquery-1.3.2.min.js” and the other is called “ui.datepicker.js”. Now please refer to the following code,
6How to perform validation with Data Annotation Validators? [Top]
MVC 2 supports a subset of DataAnnotations. MVC 3 supports the complete set. See How to: Validate Model Data Using DataAnnotations Attributes
The System.ComponentModel.DataAnnotations namespace includes the following validator attributes.
Attribute
Function
Range
Enables you to validate whether the value of a property falls between a specified ranges of values
ReqularExpression
Enables you to validate whether the value of a property matches a specified regular expression pattern.
Required
Enables you to mark a property as required.
StringLength
Enables you to specify a maximum length for a string property.
Validation
The base class for all validator attributes.
7How to call action method with JQuery? [Top]
It’s very easy to call the action method by using the jQuery. We just need to call the $.ajax method. You can find the detailed information about the method from jQuery website. The following example gets regions JSON data from server and adds mouseover and mouseout event for each region item. When the mouse is over on an item, the corresponding attractions data will be requested by using jQuery Ajax.
Please refer the following code,
8How to deploy MVC on IIS? [Top]
The ASP.NET MVC framework depends on ASP.NET Routing to route browser requests to controller actions. In order to take advantage of ASP.NET Routing, you might have to perform additional configuration steps on your web server. It all depends on the version of Internet Information Services (IIS) and the request processing mode for your application. We will focus on two easiest ways to deploy MVC on IIS.
IIS7
We don’t need to perform any special configuration step when using IIS 7.0 in integrated mode.
IIS 6
The method is to create something called a wildcard script map. A wildcard script map enables you to map every request into the ASP.NET framework.
Right-click a website and select Properties
Select the Home Directory tab
Click the Configuration button
Select the Mappings tab
Click the Insert button (see http://static.asp.net/asp.net/images/mvc/08/CS/image008.jpg)
Paste the path to the aspnet_isapi.dll into the Executable field (you can copy this path from the script map for .aspx files)
Uncheck the checkbox labeled Verify that file exists
Click the OK button
IIS5
Right-click your application virtual directory on inetmgr.exe.
Add a new mapping extension. The extension should be.*, which will be mapped to the Executable C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll, or the appropriate location on your computer (simply copy this from the mapping for .aspx files). On the mapping uncheck "check that file exists".
We can find more resource from the following website.
Vince Xu - M...
All-Star
80367 Points
6801 Posts
FAQ in ASP.NET MVC
Apr 08, 2010 01:21 AM|LINK
The MVC FAQ .
0 Where do I get the tools to get started with ASP.NET?
1 How to get started with MVC?
2 How to realize a grid view with ASP.NET MVC?
3 What is the difference between ViewData and TempData?
4 How to choose between ASP.NET Web Forms and MVC?
5 How to get started on jQuery with MVC?
6 How to perform validation with Data Annotation Validators?
7 How to call action method with jQuery?
8 How to deploy MVC on IIS?
9 Where can I learn more about the ASP.NET MVC 2 release?
0 Where do I get the tools to get started with ASP.NET? [Top]
ASP.NET MVC 3
1 How to get started with MVC? [Top]
Intro to MVC 3
Remote Validation
How to: Validate Model Data Using DataAnnotations Attributes
Walkthrough: Using Templated Helpers to Display Data in ASP.NET MVC
How to: Implement Remote Validation from a Client in MVC
When a newbie first contact with MVC, most of them wonder about how to start with MVC.
There are many videos and articles which talk about how to start with MVC .Here we suggest the newbie to start with the following three videos,
1. http://www.asp.net/learn/mvc-videos/video-7093.aspx
Creating NerdDinner.com with Microsoft ASP.NET Model View Controller (MVC)
2. http://www.asp.net/learn/mvc-videos/video-7094.aspx
America's Next Top Model View Controller Framework
3. http://www.asp.net/learn/mvc-videos/video-7095.aspx
Ninja on Fire Black Belt Tips
The videos above will show us how to use MVC to build websites. After finishing the videos, we can get the basic principle from the link below if we want:
http://www.asp.net/learn/mvc/
We can also get more information on this topic from the following website.
http://blogs.msdn.com/rickandy/archive/2009/10/15/mvc-faq.aspx
2 How to realize a grid view with ASP.NET MVC ?[Top]
The question how to implement the GridView with ASP.NET MVC is often asked on the ASP.NET MVC forums. There are many answers and we pick some popular ones as a FAQ for your reference.
The sample is quite simple and easy to use; first let us check this code below about the definition of ‘PaginatedList’ class.
We don’t need to perform any special configuration step when using IIS 7.0 in integrated mode.
The method is to create something called a wildcard script map. A wildcard script map enables you to map every request into the ASP.NET framework.
We can find more resource from the following website.
http://blogs.msdn.com/rickandy/archive/2009/10/15/mvc-faq.aspxYou can find more information about the validation from the following website.
http://www.asp.net/learn/mvc/tutorial-39-cs.aspx
9 Where can I learn more about the ASP.NET MVC 2 release? [Top]
Check out Phil Haack's post: ASP.NET MVC 2 RTM!