MVC模式在ASP.NET中的应用2011-10-25

介绍在网上搜寻了很长时间后却不能够找到一个演示ASP.NET的MVC模型的例子. 于是我实现了一个很好的能够领略MVC模型的简单实例.有关 MVC在一个传统的应用程序中,一个单一代码要处理所有事物。 藉由MVC模型,你可以将你的应用程序有机的分成三个协作的部份: 模型,视图和控制器。视图是直接面向用户使用的部份。它格式化数据使数据以各种形式展现在荧屏上。然而实际上,它不包含数据。数据包容在模型中。最后,控制器部分接受用户操作命令进而修正模型内的数据。更多的有关MVC方面的知识可以到下面的连接http://www.uidesign.net/1999/papers/webmvc_part1.html模型假定你知道MVC模型, 我要给你的这一个例子将演示如何在ASP.NET中实现MVC模式。模型是你所有的商业逻辑代码片段所在。我这里给出一个类实现二个数字相加,并把结果送回用户界面。
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 applicationpublic class Model{public Model(){}// static method for adding two numbers//// @params int a,b - numbers to be added// @return c - resultpublic static int Add(int a, int b){int c = a + b;return c;}// static nethod to add two numbers//// @params string a,b - numbers to be added// @return int c - resultpublic static int Add(string a, string b){int c = Int32.Parse(a) + Int32.Parse(b);return c;}}}