ProMesh.NET Quick Walkthrough - Part 2

We'll take our class from the previous example, and do a little bit extra:

[Layout("master")] [View("home")]
public class Home : Page
{
   public class Employee
   {
       public Employee(string name, decimal salary) { Name = name; Salary = salary }

       public string Name;
       public decimal Salary;
   }

   public void Run()
   {
      List<Employee> employees = new List<Emplyee>();

      employees.Add( new Employee("Mark Jones" , 65000) );
      employees.Add( new Employee("John Doe" , 83000) );
      employees.Add( new Employee("Phil Baxter" , 125000) );

      ViewData["Employees"] = employees;
   }
}


home.htm
<html>
<body>
<table>
<tr><th>Name</th><th>Salary</th></tr>
<!--$(foreach employee in Employees)-->
<tr><td>$(employee.Name)</td><td>$(employee.Salary)</td></tr>
<!--$(endfor)-->
</table>
</body>
</html>


Pretty simple, isn't it?

The final output will be:
<html>
<head><title>My first ProMesh.NET page</title></head>
<body>
<table>
<tr><th>Name</th><th>Salary</th></tr>
<tr><td>Mark Jones</td><td>65000</td></tr>
<tr><td>John Doe</td><td>83000</td></tr>
<tr><td>Phil Baxter</td><td>125000</td></tr>
</table>
</body>
</html>


Want to format the numbers a little?

home.htm
<html>
<body>
<table>
<tr><th>Name</th><th>Salary</th></tr>
<!--$(foreach employee in Employees)-->
<tr><td>$(employee.Name)</td><td>$(employee.Salary:#,##0.00)</td></tr>
<!--$(endfor)-->
</table>
</body>
</html>


Final output:
<html>
<head><title>My first ProMesh.NET page</title></head>
<body>
<table>
<tr><th>Name</th><th>Salary</th></tr>
<tr><td>Mark Jones</td><td>65,000.00</td></tr>
<tr><td>John Doe</td><td>83,000.00</td></tr>
<tr><td>Phil Baxter</td><td>125,000.00</td></tr>
</table>
</body>
</html>


Next: Conditional sections

Last edited Jul 28, 2007 at 3:39 PM by activa, version 2

Comments

No comments yet.