我们继续上一个例子,添加一些代码用来显示一个表格:
Home.cs:
home.htm:
下面是渲染后的结果:
对应的Html:
做些修改,对输出的数字进行格式化:
home.htm:
结果:
对应的Html:
Home.cs:
1
[Layout("master")] [View("home")]
2
public class Home : PageController
3
{
4
public class Employee
5
{
6
public Employee(string name, decimal salary) { Name = name; Salary = salary }
7
8
public string Name;
9
public decimal Salary;
10
}
11
12
public void Run()
13
{
14
List<Employee> employees = new List<Emplyee>();
15
16
employees.Add( new Employee("Mark Jones" , 65000) );
17
employees.Add( new Employee("John Doe" , 83000) );
18
employees.Add( new Employee("Phil Baxter" , 125000) );
19
20
ViewData["Employees"] = employees;
21
}
22
}
23
[Layout("master")] [View("home")]2
public class Home : PageController3
{4
public class Employee5
{6
public Employee(string name, decimal salary) { Name = name; Salary = salary }7
8
public string Name;9
public decimal Salary;10
}11
12
public void Run()13
{14
List<Employee> employees = new List<Emplyee>();15
16
employees.Add( new Employee("Mark Jones" , 65000) );17
employees.Add( new Employee("John Doe" , 83000) );18
employees.Add( new Employee("Phil Baxter" , 125000) );19
20
ViewData["Employees"] = employees;21
}22
}23

home.htm:
1
<html>
2
<body>
3
<table>
4
<tr><th>Name</th><th>Salary</th></tr>
5
<!--$[foreach employee in Employees]-->
6
<tr><td>$[employee.Name]</td><td>$[employee.Salary]</td></tr>
7
<!--$[endfor]-->
8
</table>
9
</body>
10
</html>
11
<html>2
<body>3
<table>4
<tr><th>Name</th><th>Salary</th></tr>5
<!--$[foreach employee in Employees]-->6
<tr><td>$[employee.Name]</td><td>$[employee.Salary]</td></tr>7
<!--$[endfor]-->8
</table>9
</body>10
</html>11

下面是渲染后的结果:
| Name | Salary |
|---|---|
| Mark Jones | 65000 |
| John Doe | 83000 |
| Phil Baxter | 125000 |
对应的Html:
1
<html>
2
<head><title>My first ProMesh.NET page</title></head>
3
<body>
4
<table>
5
<tr><th>Name</th><th>Salary</th></tr>
6
<tr><td>Mark Jones</td><td>65000</td></tr>
7
<tr><td>John Doe</td><td>83000</td></tr>
8
<tr><td>Phil Baxter</td><td>125000</td></tr>
9
</table>
10
</body>
11
</html>
12
<html>2
<head><title>My first ProMesh.NET page</title></head>3
<body>4
<table>5
<tr><th>Name</th><th>Salary</th></tr>6
<tr><td>Mark Jones</td><td>65000</td></tr>7
<tr><td>John Doe</td><td>83000</td></tr>8
<tr><td>Phil Baxter</td><td>125000</td></tr>9
</table>10
</body>11
</html>12

做些修改,对输出的数字进行格式化:
home.htm:
1
<html>
2
<body>
3
<table>
4
<tr><th>Name</th><th>Salary</th></tr>
5
<!--$[foreach employee in Employees]-->
6
<tr><td>$[employee.Name]</td><td>$[employee.Salary:#,##0.00]</td></tr>
7
<!--$[endfor]-->
8
</table>
9
</body>
10
</html>
11
<html>2
<body>3
<table>4
<tr><th>Name</th><th>Salary</th></tr>5
<!--$[foreach employee in Employees]-->6
<tr><td>$[employee.Name]</td><td>$[employee.Salary:#,##0.00]</td></tr>7
<!--$[endfor]-->8
</table>9
</body>10
</html>11

结果:
| Name | Salary |
|---|---|
| Mark Jones | 65,000.00 |
| John Doe | 83,000.00 |
| Phil Baxter | 125,000.00 |
对应的Html:
1
<html>
2
<head><title>My first ProMesh.NET page</title></head>
3
<body>
4
<table>
5
<tr><th>Name</th><th>Salary</th></tr>
6
<tr><td>Mark Jones</td><td>65,000.00</td></tr>
7
<tr><td>John Doe</td><td>83,000.00</td></tr>
8
<tr><td>Phil Baxter</td><td>125,000.00</td></tr>
9
</table>
10
</body>
11
</html>
12
<html>2
<head><title>My first ProMesh.NET page</title></head>3
<body>4
<table>5
<tr><th>Name</th><th>Salary</th></tr>6
<tr><td>Mark Jones</td><td>65,000.00</td></tr>7
<tr><td>John Doe</td><td>83,000.00</td></tr>8
<tr><td>Phil Baxter</td><td>125,000.00</td></tr>9
</table>10
</body>11
</html>12



浙公网安备 33010602011771号