ProMesh.net试用(4)-接收客户端数据

在ProMesh应用中,一个控制器有3种方式接收浏览器客户端传来的参数:

1、在方法的参数签名中定义:
 1 public   class  EmployeeDetail : PageController
 2 {
 3   public void Run(int id, string action)
 4   {
 5      Employee employee = new Employee(id);
 6      
 7      if (action == "delete")
 8      {
 9          employee.Delete();
10      }

11      else
12      {
13          ViewData["CurrentEmployee"= employee;
14      }

15   }

16}

17
在上面的例子中,控制器的Run方法定义的“id”和“action”两个参数。
如果有这样Url请求:http://www.yoursite.com/emplyeedetail.ashx?id=5&action=delete,url中id和action参数将会被传递给Run方法的id和action参数;如果url没有带某个相应的参数,则此参数的值为null(或者为参数类型的默认值)。

2、在类中定义字段或属性:
在所需字段定义以下中的某种Attribue:[Get]、[Post]、[GetOrPost]。
 1 public   class  EmployeeDetail : PageController
 2 {
 3   [Get("id")]
 4   private int _id;
 5 
 6   public void Run(string action)
 7   {
 8      Employee employee = new Employee(_id);
 9      
10      if (action == "delete")
11      {
12          employee.Delete();
13      }

14      else
15      {
16          ViewData["CurrentEmployee"= employee;
17      }

18   }

19}

20
上面的_id字段将被映射到url中的“id”参数。

3、在代码中通过调用ProMesh的API显式地取得数据:
下面的代码中通过调用GetData取得Get方式传递的数据,通过PostData相应地可以取得Post参数:
 1 public   class  EmployeeDetail : PageController
 2 {
 3   public void Run()
 4   {
 5      int id = GetData.Get<int>("id"); // uses the Get() method (generic version)
 6      string action = GetData["action"];  // uses the indexer
 7 
 8      Employee employee = new Employee(id);
 9      
10      if (action == "delete")
11      {
12          employee.Delete();
13      }

14      else
15      {
16          ViewData["CurrentEmployee"= employee;
17      }

18   }

19}

20
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值