Introduction
A few hours ago I started a website in Nancy. Now I want to show data I have in my webpage.
And here the docs were not all that helpfull. But I made it.
The Model
First of all I need a Model.
- Namespace Model
- Public Class PlantsModel
- Public Property Id As Integer
- Public Property Name As String
- Public Property LatinName As String
- End Class
- End Namespace
And I put that in a Model folder. I ended with Model since that is the convention but not really needed in all cases.
The View
Time to move on to more exiting things.
I created a Plants.html file.
I used the SuperSimpleViewEngine for this.
As you see I just add the @Model. and then the name of the property I want. Simples.
Now I just need to tell my controller what to do.
The Controller
I guess we can call our module our controller.
- Imports WebApplication2.Model
- Imports Nancy
- Public Class PlantsModule
- Inherits NancyModule
- Public Sub New()
- MyBase.Get("/plants") = Function(parameters)
- Return View(New PlantsModel() With {.Id = 2, .Name = "test"})
- End Function
- End Sub
- End Class
So the url http://localhost/plants will take you to the page Plants.htmland will inject the PlantsModel I just created in there. By convention the fact that you inject a PlanstModel in there informs Nancy that you want to use the Plant.html view.
You could have written this instead.
- Imports WebApplication2.Model
- Imports Nancy
- Public Class PlantsModule
- Inherits NancyModule
- Public Sub New()
- MyBase.Get("/plants") = Function(parameters)
- Return View("Plants.html", New PlantsModel() With {.Id = 2, .Name = "test"})
- End Function
- End Sub
- End Class
Or any other html.
And that gives us this amazing page.
Conclusion
Slightly harder than it should have been because I could not find the correct docs that explained this simply. But I got it working anyway.




LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.