ProMesh.NET Quick Walkthrough - Part 1 - Hello World
Web applications built with ProMesh.NET are controller-based. This means that when a page is retrieved from the web server, a controller object will be instantiated and one or more methods are executed, after which the controller decides what
view to display. The view is then rendered to the web browser.
When you are familiar with controllers and views, this may sound familiar, but we will give a simple example to show how it works.
Let's create a simple controller class
Home:
[Layout("master")]
[View("home")]
public class Home : PageController
{
public void Run()
{
ViewData["HelloText"] = "Hello World!";
}
}
When you type "
http://www.yourwebsite.com/home.ashx" in your web browser, the Run() method will be executed.
As you can see, there are two attributes defined on the
Home class. These define what templates to render. The [Layout] attribute defines the
master template, while the [View] attribute defines the
inner template.
For the above example, we'll need two HTML templates:
master.htm
<html>
<head><title>My first ProMesh.NET page</title></head>
<body>
$[_VIEW_]
</body>
</html>
home.htm
<html>
<body>
$[HelloText]
</body>
</html>
Note that the
home.htm file has <html> and <body> sections. These are not needed, but are allowed. Only the portion between the <body> and</body> tags will be included in the final output. (the
master.htm file already has these tags.
The final output will be:
Hello World
HTML:
<html>
<head><title>My first ProMesh.NET page</title></head>
<body>
Hello World!
</body>
</html>
Next:
Add some looping