Helper in Monorail is bound to the Controller.
Shape: [Helper (typeof (ChHelper)]
Abstract public class BaseBlockController: SmartDispatcherController {
}
However, Helper is used in View, so Monorail is slightly different from the separation method.
So how does Asp.net MVC bind a custom Helper?
In fact, the View of Asp.net MVC also has code files similar to index. aspx. cs.
Code files inherit from ViewPage
The following example is used:
First, I will customize a Helper
Small extensions of strings are implemented. Public class StringHelper
{
Public string Red (string str ){
Return string. Format (@ "<span style =" "color: red" ">{0} </span>", str );
}
Public string Green (string str ){
Return string. Format (@ "<span style =" "color: green" ">{0} </span>", str );
}
}
So how can we use it in View?
We can write the following code in View cs: Public StringHelper Str {
Get;
Set;
}
That is Public partial class Index: ViewPage
{
Public StringHelper Str {
Get;
Set;
}
}
In this way, we can use <% = Str. Red (ViewData ["title"]) %>
Such code
If you want to use Helper not only in this file
You can write the attribute in the base class of a BaseViewPage, and then all views are inherited from the custom BaseViewPage.
Similarly, you can use a similar method to use the custom Helper in the Master file.