MVC mode application introduction: When I experienced a long time in the process of web development, I still didn't find some good code to illustrate the MVC mode development under ASP.NET. I have listed a simple example that gives a good method or process for using MVC. About MVC In traditional applications, a single code handles all things. But with MVC, you can divide your program into part of our work together: Model, View, and Controller (for a unique name, individual thinks unnecessary fully translation, this effect will be better). View is the part you can see, it formats the data and presents before the user's eyes. However, in fact, it does not contain data. The data belongs to Model. Finally, the Controller handles the command submitted and modifies Model. Want to know more about MVC, please open the link below: http://www.uidesign.net/1999/papers/webmvc_part1.html
MODEL: Maybe you know very well for MVC, but I still give a simple code, which shows how to perform MVC in ASP.NET. Model is part of all of the business logic processing. The following class is only two numbers and send the result back. <----------------------------------------------- ---------------------------------> using system;
namespace MVCTest {/// This class is where we have the business logic build in. /// It is a managed library that will be referenced by /// your web application public class Model {public Model () {} // static Method for adding two number // @Params Int a, b - numbers to be added @return c - result public static int Add (int A, int b) {int C = a b; returnif
// static nethod to add two numbers // @Params String a, b - number int c - result public static int add (string a, string b) {int c = int32.parse a) int32.Parse (b); return c;}}} <------------------------------- -------------------------------------------------> Controller: In ASP.NER, you usually access the server directly. Instead of the server is a potential controller, it is the main entrance port. This will not provide a central control center, if you first want to use the server, or any public processing process will further occur in all the server. However, all your code-behind's pages are inherited. One public class is system.web.ui.page, you can put all the initialized code in an online () event, which is overloaded Whenever the page is read when read at any time, the page class of the page class () is performed. Now, anywhere in your code, you can reposition and connect to a new ASPX page. You can get the name of the page that will be jumped by calling getServicePage (). If you want to rename an ASPX page file, you can immediately modify the name of the file and change GetServicePage, you can still work, this part is the ASPX page we have and it needs to be used. Supported Code-Behind class. In the following example, I wrote 2 ASPX pages, one for obtaining the user's input to calculate 2 numbers, while the other outputs the result.
This is the View1.asp page: <% @ page language = "c #" codebehind = "view1.aspx.cs" autoeventwireup = "false" inherits = "mvcapplication.View1"%>