View从Action中获得数据和html helper function(转载)
2020-11-18 12:20
阅读:808
标签:com blog style class div code c log t sp width
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
@model MvcApplication1.Models.M_Person @ using
MvcApplication1.Models;
@{ ViewBag.Title = "GetData" ;
var
p = ViewData[ "data" ] as
M_Person;
var
p2 = ViewBag.Data as
M_Person;
}
GetData
@{ int
i = 1;}
@*@helper ChangeColor( int
age)
{
if
(age > 90)
{
}
else
{
@age
}
}*@ @*@functions{ public
IHtmlString ChangeColor( int
age)
{
if (age>90)
{
return
new HtmlString( "" +age+ "" );
} else
{
return
new HtmlString(age + "" );
}
}
}*@
|
UIHelper.cshtml
?
1
2
3
4
5
6
7
8
9
10
11
12
|
@helper ChangeColor( int
age)
{ if (age>90)
{
} else
{
@age }
} |
UIFunctions.cshtml
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
@functions{ public
static IHtmlString ChangeColor( int
age)
{
if
(age > 90)
{
return
new HtmlString( ""
+ age + "" );
}
else
{
return
new HtmlString(age + "" );
}
}
} |
controller
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
public
ActionResult GetData()
{
M_Person person = new
M_Person() { Name = "济公活佛" , Age = 90 };
ViewData[ "data" ] = person;
ViewData.Model = person;
ViewBag.Data = person;
List new
List
new
Models.M_Person() { Name = "济公活佛" , Age = 90 },
new
Models.M_Person() { Name = "广亮和尚" , Age = 88 },
new
Models.M_Person() { Name = "怄气禅师" , Age = 45 },
new
Models.M_Person() { Name = "飞龙僧" , Age = 123 }
};
ViewBag.Persons = list;
return
View();
}
|
View从Action中获得数据和html helper function(转载),搜素材,soscw.com
View从Action中获得数据和html helper function(转载)
标签:com blog style class div code c log t sp width
原文地址:http://www.cnblogs.com/yhf286/p/3701176.html
下一篇:JS and DOM 对象列表
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:View从Action中获得数据和html helper function(转载)
文章链接:http://soscw.com/index.php/essay/21850.html
文章标题:View从Action中获得数据和html helper function(转载)
文章链接:http://soscw.com/index.php/essay/21850.html
评论
亲,登录后才可以留言!