介绍
在网上搜寻了很长时间后却不能够找到一个演示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 application public class Model { public Model() { } // static method for adding two numbers // // @params int a,b - numbers to be added // @return c - result public 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 - result public static int Add(string a, string b) { int c = Int32.Parse(a) + Int32.Parse(b); return c; } } }
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索int
, 数据
, mvc
, 模型
, numbers
, add two numbers
, mvc c
, c # mvc
一个
,以便于您获取更多的相关知识。