MVC 2.0 learning notes and Demo sharing

Source: Internet
Author: User

I haven't written a BLOG for a long time. I may not have any new technical discoveries, and I don't know what to share with you here. Recently, we have been studying MVC 2.0. We all know that software systems are divided into three basic parts: Model, View, and Controller ). If it is good, it is indeed good, and it is easy to develop. If it is not good, there are also some problems. For example, the risk of version upgrade, performance comparison research is not profound at present. When I first started learning, I found the same information on the Internet, and most of them are about MVC1.0. In order to reduce the detours for beginners, I would like to share my learning experience with you. I will not give a lecture by the official staff ...... now, I think it's a big step to get started.

 

To use this first step: Install AspNetMVC2_VS2008.exe. You can download this item from many places on the Internet to see what version of your VS is, after downloading and installing the template, you will see:; create an "Asp. net MVC 2 Web Application ", and then the pop-up will ask you if you want to create a test project, we choose no. Then the system will automatically create some problems. These files are the templates we have learned. It doesn't matter if we don't understand the principles. Just draw a few images and you will understand them. After the project is created, let's talk about the use of the files in it. There are several original directories in our View file. What we need to clarify is that controller is a folder and action is a page. For example, to view Index. aspx in the Home directory, you must set it in Global. asax in the root directory:

 

Public static void RegisterRoutes (RouteCollection routes)
{
Routes. IgnoreRoute ("{resource}. axd/{* pathInfo }");

Routes. MapRoute (
"Default", // Route name
"{Controller}/{action}/{id}", // URL with parameters
New {controller = "Home", action = "Index", id = UrlParameter. Optional} // Parameter defaults
);

}

 

If you know how to browse the file, let's take a look at how to Add View. There are several options for adding View: Empty files and strong data files. It is best to use empty files for beginners, because you need to modify some items for strong data types. We create a new folder D1, and then create V1.aspx under D1; then we cannot browse it like above, because we need to add the corresponding control in the class file under the Controllers folder directory.

For example: public ActionResult V1 ()
{
Return View ();
}

This is the case. Otherwise, the system prompts "/server error in the application.The resource cannot be found.".

Simply Add View. Let's take a look at how to use it. At the beginning, let's take a look at the value transfer method:

ViewData ["myDate"] = "test the simple value passing through ViewDate, which is limited to the current page ";
TempData ["myTempDate"] = "test the simple value passing through TempDate. It can be used as the value passing between page jumps, but it can only be used once. The second request will not be used ";

ViewDate is a powerful tool. It can store everything, such as string, List, And DataTable. If there is no problem with the entity of a class, you just need to think about Session. All my demos have instances.

Another part of the value transfer is the link value transfer. For example, we create a link in V4:
<% = Html. ActionLink ("test link transfer to V5", "V5", "D1 ",
New {word = "first value word", key = "second value: key", uid = "third value: uid "}, new {@ class = "D1 "}
) %>

In this way, a link is created. The first parameter is "link text", the second parameter is "link page to jump to", and the third parameter is "folder ", the fourth parameter is "link Parameters ";

There are two ways to accept the above link on the V5 page:

/// <Summary>
/// Method 1
/// </Summary>
/// <Param name = "word"> </param>
/// <Returns> </returns>
Public ActionResult V5 (string word, string key, string uid)// The variable name defined here must be the same as the name on the link.
{
ViewData ["qt"] = word + key + uid;

Return View ();
}
/// <Summary>
/// Method 2
/// </Summary>
/// <Returns> </returns>
Public ActionResult V5 ()
{
ViewData ["qt"] = Request. queryString ["word"]. toString () + Request. queryString ["key"]. toString () + Request. queryString ["uid"]. toString ();

Return View ();
}

This is a frequently used link for transferring values.

 

It's okay to get started with the basics, and you have to mine it on your own. In the Demo, you can also select a strongly typed Method for form submission, registration, login, and Add View.

 

Demo address: http://files.cnblogs.com/teracy/Demo100528.zip

 

 

 

 

 

 

 

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.