Tour of MonoRail Series
Due to a spell of blogger’s block, I thought I would do a series postings to help me get past it. This post begins a series on highlighting various features of the Castle Project MonoRail. All series will be examples from the MonoRail trunk. Some of the features I will be discussing are only available on the trunk (specifically the new Routing Module). To start off the series. The first part will cover MonoRail helpers. The series will have the following topics:
Part 2. UI Basics (Layouts, Views and Shared Views, View Components)
Part 3. Using the new Routing Module
Part 4. Authentication/Security
Part 6. Using JsonReturnBinder for serializing to JSON
Part 7. Creating Wizards using IWizardController
1: $FormHelper.TextField(“blogpost.title”)
1: <input type=“text” id=“blogpost_title” name=“blogpost.title” />
1: public void CreateBlogPost([DataBind(“blogpost”)] BlogPost blogpost) {}
As long as you specify the correct id prefix as it appears in your template, MonoRail will do all the binding on the controller. Your controller must also derive from SmartDispatcherController otherwise you will get an exception at runtime. There are many more features that are provided with FormHelper that I will leave you to explore here. There are a number of other helpers available such as AjaxHelper, UrlHelper and DateFormatHelper.
If you want to create your own Helper for whatever task you have at hand all you need to do is create a class and then add an attribute to any controllers that wish to use the helper. The code would look like so:
1: public class MyCoolHelper
2: {
3: public string DoSomethingCool()
4: {
5: return “cool stuff”;
6: }
7: }
1: [Helper(typeof(MyCoolHelper))]
2: public class SomeController
3: {
4: }
It’s as easy as that. This first post is pretty basic. I wanted to start off simple and work up to some of the other topics such as Dynamic Actions and doing Ajax/JSON related data retrieval.
Next time we will go over layouts, views and view components. Should be a fun time!</FONT>
</p>