关于Controller
Controller是什么?
Controller的历史
定义一个Controller
使用IController接口
Public interface Icontroller{
void Execute(RequestContextrequestcontext);
}
using System.Web.Mvc;
using System.Web.Routing;
public class SimpleController: IController{
public void Execute(RequestContextrequestContext){
var
response = requestContext.HttpContext.Response;
response.Write(“<h1>Hello World!</h1>”);
}}
名字后面一定要叫Controller,不然Route不认识。
Controller的基础类实现
-IControllerBase接口
Controller类和Action类
System.Web.Controller
using System;using System.Web;using System.Web.Mvc;public class SimpleController: Controller{public void Hello(){response.Write(“<h1>Hello World!</h1>”);}}public void Goodbye(string name)
{
Response.Write(“Goodbye” + HttpUtility.HtmlEncode(name));
}
url:/simple2/goodbye?name=World
url:/simple2/goodbye/world
使用多个参数
public void Distance(int x1, int y1, int x2, int y2)
{
double xSquared= Math.Pow(x2 -x1, 2);
double ySquared= Math.Pow(y2 -y1, 2);
Response.Write(Math.Sqrt(xSquared+ ySquared));
}
/simple2/distance?x2=1&y2=2&x1=0&y1=0
routes.MapRoute(“distance”,“simple2/distance/{x1},{y1}/{x2},{y2}”,new { Controller = “Simple2”, action = “Distance” });
/simple2/distance/0,0/1,2
默认URL
public ActionResultDinnersNearMe(string location, intmaxDinners= 10)
{}
2011-4-17 16:00 danny
Controller是什么?
Controller的历史
定义一个Controller
使用IController接口
Public interface Icontroller{
void Execute(RequestContextrequestcontext);
}
using System.Web.Mvc;
using System.Web.Routing;
public class SimpleController: IController{
public void Execute(RequestContextrequestContext){
var
response = requestContext.HttpContext.Response;
response.Write(“<h1>Hello World!</h1>”);
}}
名字后面一定要叫Controller,不然Route不认识。
Controller的基础类实现
-IControllerBase接口
Controller类和Action类
System.Web.Controller
using System;using System.Web;using System.Web.Mvc;public class SimpleController: Controller{public void Hello(){response.Write(“<h1>Hello World!</h1>”);}}public void Goodbye(string name)
{
Response.Write(“Goodbye” + HttpUtility.HtmlEncode(name));
}
url:/simple2/goodbye?name=World
url:/simple2/goodbye/world
使用多个参数
public void Distance(int x1, int y1, int x2, int y2)
{
double xSquared= Math.Pow(x2 -x1, 2);
double ySquared= Math.Pow(y2 -y1, 2);
Response.Write(Math.Sqrt(xSquared+ ySquared));
}
/simple2/distance?x2=1&y2=2&x1=0&y1=0
routes.MapRoute(“distance”,“simple2/distance/{x1},{y1}/{x2},{y2}”,new { Controller = “Simple2”, action = “Distance” });
/simple2/distance/0,0/1,2
默认URL
public ActionResultDinnersNearMe(string location, intmaxDinners= 10)
{}
2011-4-17 16:00 danny
发表评论
-
10.2Asp.net MVC各层使用TDD方式
2011-05-01 12:09 775Asp.net MVC各层使用TDD方式 Asp.net M ... -
10.1TDD简介
2011-04-30 23:09 536MVC中的测试驱动开发 为什么需要TDD TDD的由来 它 ... -
9、MVC程序安全限定
2011-04-29 22:14 1788常见网络安全攻击隐患 针对Asp.net MVC防御体系 安 ... -
8.2ASP.NET MVC2使用Ajax类库实例
2011-04-29 13:05 897ASP.NET MVC2使用Ajax类库实例 .net fo ... -
8.1Ajax类库介绍
2011-04-28 09:12 859在ASP.NET MVC中使用 -Microsoft ASP. ... -
7.2自定义开发Filter
2011-04-27 16:04 599Custom Filters ➤IAuthorization ... -
7.1Filter的使用
2011-04-26 22:20 481Filter的使用 -对Action的附加说明 Asp.n ... -
6.3Action的调用与属性
2011-04-26 09:43 649Action的调用与属性 1、唤起Action R ... -
6.2ActionResult的使用
2011-04-25 19:14 657ActionResult public abstract c ... -
5.6在Webform中使用routing
2011-04-23 22:48 638在Webform中使用routing 在Asp.net 4中使 ... -
5.5URL和Action匹配的秘密
2011-04-22 09:11 872Routes是如何把URL映射为Action -请求路由管道 ... -
5.4使用routing生成URL
2011-04-21 11:05 575使用routing生成URL URL生成器概述 1、质询每个 ... -
5.3使用Routes
2011-04-20 09:11 7205.3使用Routes 注册Area Route publi ... -
5.2Routes匹配URL的工作方式
2011-04-19 08:55 831URL的匹配规则 -site/{controller}/{ac ... -
5.1Url和Routes介绍
2011-04-17 12:05 6255.1Url和Routes介绍 关于Urls -域名好记好拼 ... -
4、View引擎介绍
2011-04-16 22:03 624View引擎介绍 Request =>Routing= ... -
3、HtmlHelper类(续)
2011-04-16 13:41 627HtmlHelper类(续) Html.TextArea 用 ... -
2、HtmlHelper类
2011-04-15 22:33 1073HtmlHelper类 <%Html. MVC1 & ... -
1、View层
2011-04-15 09:06 606ViewDataDictionary类 View 负责输出 ...
相关推荐
6.1宏的基本操作
数字电子技术基础课件:6.1 脉冲的基本知识 .ppt
DEFORM-3D_v6.1基本操作指南
CWnd类的引出
力控6.1版本破解力控6.1版本破解力控6.1版本破解力控6.1版本破解力控6.1版本破解力控6.1版本破解力控6.1版本破解
网人分类信息程序 演示 http://www.handan5.com 6.1最新版
EhLib 6.1 Build 6.1.129最新版,从官网下载的,可支持最新版本Delphi XE4
Windows6.1-KB2533623-x64Windows6.1-KB2533623-x64Windows6.1-KB2533623-x64Windows6.1-KB2533623-x64Windows6.1-KB2533623-x64Windows6.1-KB2533623-x64Windows6.1-KB2533623-x64Windows6.1-KB2533623-x64Windows...
skype 6.1 稳定版,非tom版不知道怎么分类,就放到网络技术了
was相关资料: Websphere安装步骤 websphere安装后配置说明 Websphere实用手册 WebSphere+v6.1配置文档
Windows6.1-KB2999226-x86
三星NVME 固态硬盘驱动,M2转PCI-E安装系统时需要注入。
DZDZ 6.1DZ 6.1DZ 6.1DZ 6.1
一年级数学下册第六单元分类6.1分类1课时练北京版202003172181
一年级数学下册第六单元分类6.1分类2课时练北京版202003172182
超级模块6.1免费版超级模块6.1免费版超级模块6.1超级模块6.1免费版免费版
MyEclipse 配置 Websphere6.1
websphere6.1.0.0升级至6.1.0.17
notepad++ 6.1 Notepad++是一套非常有特色的自由软件的纯文字编辑器(许可证:GPL),有完整的中文化接口及支援多国语言撰写的功能(UTF8 技术)。它的功能比 Windows 中的 Notepad(记事簿)强大,除了可以用来制作一般的...