在ProMesh应用中,一个控制器有3种方式接收浏览器客户端传来的参数:
1、在方法的参数签名中定义:
如果有这样Url请求:http://www.yoursite.com/emplyeedetail.ashx?id=5&action=delete,url中id和action参数将会被传递给Run方法的id和action参数;如果url没有带某个相应的参数,则此参数的值为null(或者为参数类型的默认值)。
2、在类中定义字段或属性:
在所需字段定义以下中的某种Attribue:[Get]、[Post]、[GetOrPost]。
3、在代码中通过调用ProMesh的API显式地取得数据:
下面的代码中通过调用GetData取得Get方式传递的数据,通过PostData相应地可以取得Post参数:
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”两个参数。
2



3

4



5

6

7

8



9

10

11

12



13

14

15

16

17

如果有这样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”参数。
2



3

4

5

6

7



8

9

10

11



12

13

14

15



16

17

18

19

20

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

2



3

4



5

6

7

8

9

10

11



12

13

14

15



16

17

18

19

20
