Welcome!

HandlebarsDotNet.Mvc Class Library
Welcome!

This is an ASP.NET MVC ViewEngine that uses the Handlebars syntax for its view files.

For reference:
https://github.com/rexm/Handlebars.Net - Blistering-fast Handlebars.js templates in your .NET application.
http://handlebarsjs.com/ - The syntax is described here (but note that is the client-side Javascript compiler/parser)

Getting started

How to add the view engine (assuming the source file has "using HandlebarsDotNet.Mvc;" at the top):

Global.asax.cs
Copy
protected void Application_Start()
{
    // In case you want to remove the other view engines, uncomment this:
    //ViewEngines.Engines.Clear();

    // Create the view engine.
    var hbsve = new HandlebarsViewEngine();

    // The builtin helpers aren't added by default - you need to opt-in to have them available.
    hbsve.RegisterMvcHelpers();
    hbsve.RegisterSectionsHelpers();

    // Add the Handlebars view engine
    ViewEngines.Engines.Add(hbsve);

    // The rest of the method continues here. Here is what ASP.NET MVC has by default.
    AreaRegistration.RegisterAllAreas();
    RouteConfig.RegisterRoutes(RouteTable.Routes);
}

By default view (and layout) files have an extension of ".hbs". You can change that by setting the ViewExtension property.

The files used for rendering are found in the paths returned from an IPathsProvider implementation.
If you don't specify one in the constructor for HandlebarsViewEngine then DefaultPathsProvider is used.

In order to find partials the VirtualPathProvider must support GetDirectory. Also, if it supports GetCacheDependency that will be beneficial. If it doesn't then updates to the view files are not instantaneuos - updates to the files are checked every 5 seconds. If it does support GetCacheDependency there can still be some delay depending on the implementation.

How to send a model to the view file:

C#
Copy
public class HomeController : Controller
{
    public ActionResult Index()
    {
        var model = new
        {
            first = "John",
            last  = "Doe"
        }
        return View(model);
    }
}
~/Views/Home/Index.hbs
Copy
Hello, {{first}} {{last}}!
Renders
Copy
Hello, John Doe!

The example above didn't use a layout file. This is how to do that:

~/Views/Home/Index.hbs
Copy
{{!< default}}
Hello, {{first}} {{last}}!
~/Views/_Layouts/default.hbs
Copy
<html>
<body>
{{{body}}}
</body>
</html>
Renders
Copy
<html>
<body>
Hello, John Doe!
</body>
</html>
About this help

The latest version of this help is located on the web at https://jiellse.github.io/Handlebars.Net.Mvc/

Sometimes it is useful to have documentation locally on your own computer. Maybe you are at a place with no internet connectivity, or flaky connection?

A downloadable version of this can be found at https://jiellse.github.io/Handlebars.Net.Mvc/HandlebarsDotNet.Mvc.chm. If you do download it, you may have to bring up the Properties for the file and press the Unlock button in order for it to show any content. (If there is no Unlock button this step has already been done or wasn't necessary, depending on the browser used when downloading.)

If you are currently using the help file and wish to go to the website instead, use the link above.

See Also

Other Resources

Version History


Version History

Version History

The topics in this section describe the various changes made to HandlebarsDotNet.Mvc over the life of the project.

Version History

Select a version below to see a description of its changes.

  • Version 1.0

See Also

Other Resources

Welcome!


Version 1.0

Version 1.0

Version 1.0 is currently at the beta stage.

Changes in This Release

  • Note-worthy features:

    • Configurable folder paths for views, layouts and partials with sensible defaults.

    • Uses VirtualPathProvider meaning source files can come from the file system, database, embedded resources, etc.

    • Caching is used in order to not re-compile files. Cache dependencies are setup so changes to the source will trigger a re-compilation.

    • Model types sent to the view are flexible: anonymous objects, custom view model class, dictionary, ...

    • Helpers you add to the view engine do not interfere with the global Handlebars.Net in case you use it for other purposes, for example email generation.

See Also

Other Resources

Version History


HandlebarsDotNet.Mvc Namespace

HandlebarsDotNet.Mvc Namespace
This namespace contains an implementation for using Handlebars as a view engine in ASP.NET MVC (server-side).
Classes
 | Class | Description
Public class | CompiledView | This class is used by HandlebarsView when rendering.
Public class | DefaultPathsProvider | This class is used as default by HandlebarsViewEngine to get the folder paths to be used when looking for views and other resources.
Public class | HandlebarsView | Represents the information that is needed to render a Handlebars view in ASP.NET MVC.
Public class | HandlebarsViewEngine | An ASP.NET MVC ViewEngine that uses the Handlebars syntax for its view files.
Public class | HelperException | Represents the exception that is thrown for a HandlebarsDotNet.Mvc helper.
Public class | Helpers | This class contains several useful Handlebars helpers that can be registered in the configuration.
Public class | NullLogger | A logger that does nothing. This is the default logger for HandlebarsViewEngine.
Interfaces
 | Interface | Description
Public interface | ILogger | The interface used by HandlebarsViewEngine for logging purposes.
Public interface | IPathsProvider | The interface used by HandlebarsViewEngine when getting the different paths.
Enumerations
Enumeration | Description
LoggerCategory | The different categories used for the logging component in HandlebarsViewEngine. These are the only ones (currently) used by it.
See Also

Other Resources

Handlebars.Net - Blistering-fast Handlebars.js templates in your .NET application.
Handlebars.js - The syntax is described here (but note that is the client-side Javascript compiler)


CompiledView Class

CompiledView Class
This class is used by HandlebarsView when rendering.
Inheritance Hierarchy
SystemObject
HandlebarsDotNet.MvcCompiledView

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public class CompiledView
Public Class CompiledView
public ref class CompiledView
type CompiledView =  class end

The CompiledView type exposes the following members.

Constructors
 | Name | Description
Public method | CompiledView | Initializes a new instance of the CompiledView class
Top
Properties
 | Name | Description
Public property | FileHash | The hash as returned from the VirtualPathProvider. This is if the VirtualPathProvider supports CacheDependency for the file.
Public property | Func | The compiled function.
Public property | Layout | The layout specified in the file. Null or the empty string if not specified in it. Not used when rendering.
Top
Remarks
This is what is stored in the application cache by HandlebarsViewEngine. When the view engine adds this to the cache it has knowledge of paths searched, the virtual path to the source file, etc. That info is used for the cachekey and creating the CacheDependency.
Note Note
You are not supposed to add to the cache yourself, that is handled by this view engine.
However, if you need to call HandlebarsView.Render() yourself you need to be able to create instances of this class which is why this class is public.
See Also

Reference

HandlebarsDotNet.Mvc Namespace


CompiledView Constructor

CompiledView Constructor
Initializes a new instance of the CompiledView class

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public CompiledView(
    Func<Object, string> func,
    string fileHash,
    string layout
)
Public Sub New (
    func As Func(Of Object, String),
    fileHash As String,
    layout As String
)
public:
CompiledView(
    Func<Object^, String^>^ func,
    String^ fileHash,
    String^ layout
)
new :
        func : Func<Object, string> *
        fileHash : string *
        layout : string -> CompiledView

Parameters

func
Type: SystemFunc Object, String
fileHash
Type: SystemString
layout
Type: SystemString
See Also

Reference

CompiledView Class


CompiledView Properties

CompiledView Properties

The CompiledView type exposes the following members.

Properties
 | Name | Description
Public property | FileHash | The hash as returned from the VirtualPathProvider. This is if the VirtualPathProvider supports CacheDependency for the file.
Public property | Func | The compiled function.
Public property | Layout | The layout specified in the file. Null or the empty string if not specified in it. Not used when rendering.
Top
See Also

Reference

CompiledView Class


CompiledView.FileHash Property

CompiledViewFileHash Property
The hash as returned from the VirtualPathProvider. This is if the VirtualPathProvider supports CacheDependency for the file.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public string FileHash { get; }
Public ReadOnly Property FileHash As String
    Get
public:
property String^ FileHash {
    String^ get ();
}
member FileHash : string with get

Property Value

Type: String
See Also

Reference

CompiledView Class


CompiledView.Func Property

CompiledViewFunc Property
The compiled function.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public Func<Object, string> Func { get; }
Public ReadOnly Property Func As Func(Of Object, String)
    Get
public:
property Func<Object^, String^>^ Func {
    Func<Object^, String^>^ get ();
}
member Func : Func<Object, string> with get

Property Value

Type: Func Object, String
See Also

Reference

CompiledView Class


CompiledView.Layout Property

CompiledViewLayout Property
The layout specified in the file. Null or the empty string if not specified in it. Not used when rendering.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public string Layout { get; }
Public ReadOnly Property Layout As String
    Get
public:
property String^ Layout {
    String^ get ();
}
member Layout : string with get

Property Value

Type: String
Remarks
When executing the function the layout isn't rendered. This makes it easy for this view engine to render the layout specified, a different layout or no layout at all (in MVC lingo a "partial view").
See Also

Reference

CompiledView Class


DefaultPathsProvider Class

DefaultPathsProvider Class
This class is used as default by HandlebarsViewEngine to get the folder paths to be used when looking for views and other resources.
Inheritance Hierarchy
SystemObject
HandlebarsDotNet.MvcDefaultPathsProvider

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public class DefaultPathsProvider : IPathsProvider
Public Class DefaultPathsProvider
    Implements IPathsProvider
public ref class DefaultPathsProvider : IPathsProvider
type DefaultPathsProvider =
    class
        interface IPathsProvider
    end

The DefaultPathsProvider type exposes the following members.

Constructors
 | Name | Description
Public method | DefaultPathsProvider | Initializes a new instance of the DefaultPathsProvider class
Top
Methods
 | Name | Description
Public method | GetLayoutFolders | Gets the folders for where the layout files can be for the given ControllerContext. The paths returned are in the form "~/Views/_Layouts/".
Public method | GetPartialsFolders | Gets the folders for where the partials files can be for the given ControllerContext. The paths returned are in the form "~/Views/_Partials/".
Public method | GetViewFolders | Gets the folders for where the view files can be for the given ControllerContext. The paths returned are in the form "~/Views/Home/".
Top
Properties
 | Name | Description
Public property | AllowControllerlessViewFolder | Whether to allow view files to be located directly in the Views folder. Default: .
Public property | AreasFolderName | The name of the folder where areas are located. Default: "Areas"
Public property | LayoutsFolderName | The name of the folder where layouts are located. Default: "_Layouts"
Public property | PartialsFolderName | The name of the folder where partials are located. Default: "_Partials"
Public property | SharedViewsFolderName | The folder name for shared view files (not specific to a certain controller). Set this to if you want to disable this functionality. Default: "_Shared"
Public property | ViewsFolderName | The name of the folder where views are located. Default: "Views"
Top
Remarks

The default folder paths for views are:

View Folder Path (as returned by DefaultPathsProvider) | Note | Example view file path (area: Users, controller: HomeController, action: Index)
~/Areas/{area}/Views/{controller}/ | Only if within an area. | ~/Areas/Users/Views/Home/Index.hbs
~/Areas/{area}/Views/_Shared/ | Only if within an area. Note that "_Shared" is configurable (can also be empty, and if so this is not returned). | ~/Areas/Users/Views/_Shared/Index.hbs
~/Areas/{area}/Views/ | Only if within an area, and only if AllowControllerlessViewFolder is . | ~/Areas/Users/Views/Index.hbs
~/Views/{controller}/ |  | ~/Views/Home/Index.hbs
~/Views/_Shared/ | Note that "_Shared" is configurable (can also be empty, and if so this is not returned). | ~/Views/_Shared/Index.hbs
~/Views/ | Only if AllowControllerlessViewFolder is . | ~/Views/Index.hbs

The default folder paths for layouts are:

Layout Folder Path (as returned by DefaultPathsProvider) | Note | Example layout file path (area: Users, controller: HomeController, action: Index, layout: standard)
~/Areas/{area}/Views/{controller}/_Layouts/ | Only if within an area. | ~/Areas/Users/Views/Home/_Layouts/standard.hbs
~/Areas/{area}/Views/_Layouts/ | Only if within an area. | ~/Areas/Users/Views/_Layouts/standard.hbs
~/Views/{controller}/_Layouts/ |  | ~/Views/Home/_Layouts/standard.hbs
~/Views/_Layouts/ |  | ~/Views/_Layouts/standard.hbs

The default folder paths for partials are:

Partials Folder Path (as returned by DefaultPathsProvider) | Note | Example partials file path (area: Users, controller: HomeController, action: Index, partial: search)
~/Areas/{area}/Views/{controller}/_Partials/ | Only if within an area. | ~/Areas/Users/Views/Home/_Partials/search.hbs
~/Areas/{area}/Views/_Partials/ | Only if within an area. | ~/Areas/Users/Views/_Partials/search.hbs
~/Views/{controller}/_Partials/ |  | ~/Views/Home/_Partials/search.hbs
~/Views/_Partials/ |  | ~/Views/_Partials/search.hbs
See Also

Reference

HandlebarsDotNet.Mvc Namespace


DefaultPathsProvider Constructor

DefaultPathsProvider Constructor
Initializes a new instance of the DefaultPathsProvider class

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public DefaultPathsProvider()
Public Sub New
public:
DefaultPathsProvider()
new : unit -> DefaultPathsProvider
See Also

Reference

DefaultPathsProvider Class


DefaultPathsProvider Methods

DefaultPathsProvider Methods

The DefaultPathsProvider type exposes the following members.

Methods
 | Name | Description
Public method | GetLayoutFolders | Gets the folders for where the layout files can be for the given ControllerContext. The paths returned are in the form "~/Views/_Layouts/".
Public method | GetPartialsFolders | Gets the folders for where the partials files can be for the given ControllerContext. The paths returned are in the form "~/Views/_Partials/".
Public method | GetViewFolders | Gets the folders for where the view files can be for the given ControllerContext. The paths returned are in the form "~/Views/Home/".
Top
See Also

Reference

DefaultPathsProvider Class


DefaultPathsProvider.GetLayoutFolders Method

DefaultPathsProviderGetLayoutFolders Method
Gets the folders for where the layout files can be for the given ControllerContext. The paths returned are in the form "~/Views/_Layouts/".

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual IEnumerable<string> GetLayoutFolders(
    ControllerContext controllerContext
)
Public Overridable Function GetLayoutFolders (
    controllerContext As ControllerContext
) As IEnumerable(Of String)
public:
virtual IEnumerable<String^>^ GetLayoutFolders(
    ControllerContext^ controllerContext
)
abstract GetLayoutFolders :
        controllerContext : ControllerContext -> IEnumerable<string>
override GetLayoutFolders :
        controllerContext : ControllerContext -> IEnumerable<string>

Parameters

controllerContext
Type: ControllerContext
The ControllerContext for the current request.

Return Value

Type: IEnumerable String
Returns an ordered IEnumerable<string> with the paths for HandlebarsViewEngine to check.

Implements

IPathsProviderGetLayoutFolders(ControllerContext)
See Also

Reference

DefaultPathsProvider Class


DefaultPathsProvider.GetPartialsFolders Method

DefaultPathsProviderGetPartialsFolders Method
Gets the folders for where the partials files can be for the given ControllerContext. The paths returned are in the form "~/Views/_Partials/".

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual IEnumerable<string> GetPartialsFolders(
    ControllerContext controllerContext
)
Public Overridable Function GetPartialsFolders (
    controllerContext As ControllerContext
) As IEnumerable(Of String)
public:
virtual IEnumerable<String^>^ GetPartialsFolders(
    ControllerContext^ controllerContext
)
abstract GetPartialsFolders :
        controllerContext : ControllerContext -> IEnumerable<string>
override GetPartialsFolders :
        controllerContext : ControllerContext -> IEnumerable<string>

Parameters

controllerContext
Type: ControllerContext
The ControllerContext for the current request.

Return Value

Type: IEnumerable String
Returns an ordered IEnumerable<string> with the paths for HandlebarsViewEngine to check.

Implements

IPathsProviderGetPartialsFolders(ControllerContext)
See Also

Reference

DefaultPathsProvider Class


DefaultPathsProvider.GetViewFolders Method

DefaultPathsProviderGetViewFolders Method
Gets the folders for where the view files can be for the given ControllerContext. The paths returned are in the form "~/Views/Home/".

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual IEnumerable<string> GetViewFolders(
    ControllerContext controllerContext
)
Public Overridable Function GetViewFolders (
    controllerContext As ControllerContext
) As IEnumerable(Of String)
public:
virtual IEnumerable<String^>^ GetViewFolders(
    ControllerContext^ controllerContext
)
abstract GetViewFolders :
        controllerContext : ControllerContext -> IEnumerable<string>
override GetViewFolders :
        controllerContext : ControllerContext -> IEnumerable<string>

Parameters

controllerContext
Type: ControllerContext
The ControllerContext for the current request.

Return Value

Type: IEnumerable String
Returns an ordered IEnumerable<string> with the paths for HandlebarsViewEngine to check.

Implements

IPathsProviderGetViewFolders(ControllerContext)
See Also

Reference

DefaultPathsProvider Class


DefaultPathsProvider Properties

DefaultPathsProvider Properties

The DefaultPathsProvider type exposes the following members.

Properties
 | Name | Description
Public property | AllowControllerlessViewFolder | Whether to allow view files to be located directly in the Views folder. Default: .
Public property | AreasFolderName | The name of the folder where areas are located. Default: "Areas"
Public property | LayoutsFolderName | The name of the folder where layouts are located. Default: "_Layouts"
Public property | PartialsFolderName | The name of the folder where partials are located. Default: "_Partials"
Public property | SharedViewsFolderName | The folder name for shared view files (not specific to a certain controller). Set this to if you want to disable this functionality. Default: "_Shared"
Public property | ViewsFolderName | The name of the folder where views are located. Default: "Views"
Top
See Also

Reference

DefaultPathsProvider Class


DefaultPathsProvider.AllowControllerlessViewFolder Property

DefaultPathsProviderAllowControllerlessViewFolder Property
Whether to allow view files to be located directly in the Views folder. Default: .

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public bool AllowControllerlessViewFolder { get; set; }
Public Property AllowControllerlessViewFolder As Boolean
    Get
    Set
public:
property bool AllowControllerlessViewFolder {
    bool get ();
    void set (bool value);
}
member AllowControllerlessViewFolder : bool with get, set

Property Value

Type: Boolean
Remarks
This is primarily intended to be compatible with other Handlebars setups.
See Also

Reference

DefaultPathsProvider Class


DefaultPathsProvider.AreasFolderName Property

DefaultPathsProviderAreasFolderName Property
The name of the folder where areas are located. Default: "Areas"

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public string AreasFolderName { get; set; }
Public Property AreasFolderName As String
    Get
    Set
public:
property String^ AreasFolderName {
    String^ get ();
    void set (String^ value);
}
member AreasFolderName : string with get, set

Property Value

Type: String
See Also

Reference

DefaultPathsProvider Class


DefaultPathsProvider.LayoutsFolderName Property

DefaultPathsProviderLayoutsFolderName Property
The name of the folder where layouts are located. Default: "_Layouts"

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public string LayoutsFolderName { get; set; }
Public Property LayoutsFolderName As String
    Get
    Set
public:
property String^ LayoutsFolderName {
    String^ get ();
    void set (String^ value);
}
member LayoutsFolderName : string with get, set

Property Value

Type: String
See Also

Reference

DefaultPathsProvider Class


DefaultPathsProvider.PartialsFolderName Property

DefaultPathsProviderPartialsFolderName Property
The name of the folder where partials are located. Default: "_Partials"

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public string PartialsFolderName { get; set; }
Public Property PartialsFolderName As String
    Get
    Set
public:
property String^ PartialsFolderName {
    String^ get ();
    void set (String^ value);
}
member PartialsFolderName : string with get, set

Property Value

Type: String
See Also

Reference

DefaultPathsProvider Class


DefaultPathsProvider.SharedViewsFolderName Property

DefaultPathsProviderSharedViewsFolderName Property
The folder name for shared view files (not specific to a certain controller). Set this to if you want to disable this functionality. Default: "_Shared"

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public string SharedViewsFolderName { get; set; }
Public Property SharedViewsFolderName As String
    Get
    Set
public:
property String^ SharedViewsFolderName {
    String^ get ();
    void set (String^ value);
}
member SharedViewsFolderName : string with get, set

Property Value

Type: String
Remarks
The built-in view engines in ASP.NET MVC uses the name "Shared" (without the underscore) for this.
See Also

Reference

DefaultPathsProvider Class


DefaultPathsProvider.ViewsFolderName Property

DefaultPathsProviderViewsFolderName Property
The name of the folder where views are located. Default: "Views"

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public string ViewsFolderName { get; set; }
Public Property ViewsFolderName As String
    Get
    Set
public:
property String^ ViewsFolderName {
    String^ get ();
    void set (String^ value);
}
member ViewsFolderName : string with get, set

Property Value

Type: String
See Also

Reference

DefaultPathsProvider Class


HandlebarsView Class

HandlebarsView Class
Represents the information that is needed to render a Handlebars view in ASP.NET MVC.
Inheritance Hierarchy
SystemObject
HandlebarsDotNet.MvcHandlebarsView

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public class HandlebarsView : IView,
    IViewDataContainer
Public Class HandlebarsView
    Implements IView, IViewDataContainer
public ref class HandlebarsView : IView,
    IViewDataContainer
type HandlebarsView =
    class
        interface IView
        interface IViewDataContainer
    end

The HandlebarsView type exposes the following members.

Constructors
 | Name | Description
Public method | HandlebarsView | Initializes a new instance of the HandlebarsView class using the controller context and compiled view and layouts.
Top
Methods
 | Name | Description
 | GetViewContext | Gets the ViewContext that was stored in the context when rendering began for the view.
Public method | Render | Renders the specified view context by using the specified writer object.
Protected method | SetupContext | Creates the context (Handlebars lingo for the model) and stores references to the ViewData and ViewContext.
Top
Properties
 | Name | Description
Public property | ViewData | Gets or sets the view data dictionary.
Top
See Also

Reference

HandlebarsDotNet.Mvc Namespace


HandlebarsView Constructor

HandlebarsView Constructor
Initializes a new instance of the HandlebarsView class using the controller context and compiled view and layouts.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public HandlebarsView(
    ControllerContext controllerContext,
    CompiledView view,
    CompiledView[] layouts
)
Public Sub New (
    controllerContext As ControllerContext,
    view As CompiledView,
    layouts As CompiledView()
)
public:
HandlebarsView(
    ControllerContext^ controllerContext,
    CompiledView^ view,
    array<CompiledView^>^ layouts
)
new :
        controllerContext : ControllerContext *
        view : CompiledView *
        layouts : CompiledView[] -> HandlebarsView

Parameters

controllerContext
Type: ControllerContext
The controller context.
view
Type: HandlebarsDotNet.MvcCompiledView
The compiled view.
layouts
Type: HandlebarsDotNet.MvcCompiledView
The compiled layout(s) that will surround the output from the view. This can be .
See Also

Reference

HandlebarsView Class


HandlebarsView Methods

HandlebarsView Methods

The HandlebarsView type exposes the following members.

Methods
 | Name | Description
 | GetViewContext | Gets the ViewContext that was stored in the context when rendering began for the view.
Public method | Render | Renders the specified view context by using the specified writer object.
Protected method | SetupContext | Creates the context (Handlebars lingo for the model) and stores references to the ViewData and ViewContext.
Top
See Also

Reference

HandlebarsView Class


HandlebarsView.GetViewContext Method

HandlebarsViewGetViewContext Method
Gets the ViewContext that was stored in the context when rendering began for the view.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static ViewContext GetViewContext(
    Object context
)
Public Shared Function GetViewContext (
    context As Object
) As ViewContext
public:
static ViewContext^ GetViewContext(
    Object^ context
)
static member GetViewContext :
        context : Object -> ViewContext

Parameters

context
Type: SystemObject
The context as returned by SetupContext(ViewContext).

Return Value

Type: ViewContext
The ViewContext for this view.
Examples
This example registers a helper globally for the view engine. In this case it needs the ViewContext in order to instantiate a HtmlHelper.
Note that this is only an example and doesn't include error checking.
Global.asax.cs
Copy
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("formatvalue", (writer, context, args) =>
{
    object val    = args[0];
    string format = args[1] as string;
    ViewContext viewContext = HandlebarsView.GetViewContext(context);
    HtmlHelper htmlHelper = new HtmlHelper(viewContext, viewContext.View as HandlebarsView);
    string formatted = htmlHelper.FormatValue(val, format);
    writer.Write(formatted);
});
ViewEngines.Engines.Add(hbsve);
controller
Copy
public ActionResult Index()
{
    var model = new { pi = 3.14159265358979 };
    return View(model);
}
index.hbs
Copy
{{formatvalue pi "Pi is about {0:N}"}}
Renders
Copy
Pi is about 3.14
See Also

Reference

HandlebarsView Class


HandlebarsView.Render Method

HandlebarsViewRender Method
Renders the specified view context by using the specified writer object.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual void Render(
    ViewContext viewContext,
    TextWriter writer
)
Public Overridable Sub Render (
    viewContext As ViewContext,
    writer As TextWriter
)
public:
virtual void Render(
    ViewContext^ viewContext,
    TextWriter^ writer
)
abstract Render :
        viewContext : ViewContext *
        writer : TextWriter -> unit
override Render :
        viewContext : ViewContext *
        writer : TextWriter -> unit

Parameters

viewContext
Type: ViewContext
Information related to rendering a view, such as view data, temporary data, and form context.
writer
Type: System.IOTextWriter
The writer object.

Implements

IView.Render(ViewContext, TextWriter)
See Also

Reference

HandlebarsView Class


HandlebarsView.SetupContext Method

HandlebarsViewSetupContext Method
Creates the context (Handlebars lingo for the model) and stores references to the ViewData and ViewContext.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
protected virtual Object SetupContext(
    ViewContext viewContext
)
Protected Overridable Function SetupContext (
    viewContext As ViewContext
) As Object
protected:
virtual Object^ SetupContext(
    ViewContext^ viewContext
)
abstract SetupContext :
        viewContext : ViewContext -> Object
override SetupContext :
        viewContext : ViewContext -> Object

Parameters

viewContext
Type: ViewContext
The ViewContext that contains the model.

Return Value

Type: Object
A newly created context that will be used as the model for views and layouts in HandlebarsDotNet.
Remarks
This method constructs a context object from viewContext.ViewData.Model.
The context will have a few extra properties added and those are:
"viewbag" - so a view file can use {{viewbag.title}} for example to output a ViewBag.Title property that was set in the controller,
and the other one is named in an obscure way (to minimize name clash with user properties) and contains the ViewContext that was passed to this method.

Helpers may need to get ahold of the ViewContext and in those cases they can use the HandlebarsView.GetViewContext() static method.

See Also

Reference

HandlebarsView Class


HandlebarsView Properties

HandlebarsView Properties

The HandlebarsView type exposes the following members.

Properties
 | Name | Description
Public property | ViewData | Gets or sets the view data dictionary.
Top
See Also

Reference

HandlebarsView Class


HandlebarsView.ViewData Property

HandlebarsViewViewData Property
Gets or sets the view data dictionary.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public ViewDataDictionary ViewData { get; set; }
Public Property ViewData As ViewDataDictionary
    Get
    Set
public:
virtual property ViewDataDictionary^ ViewData {
    ViewDataDictionary^ get () sealed;
    void set (ViewDataDictionary^ value) sealed;
}
abstract ViewData : ViewDataDictionary with get, set
override ViewData : ViewDataDictionary with get, set

Property Value

Type: ViewDataDictionary

Implements

IViewDataContainer.ViewData
See Also

Reference

HandlebarsView Class


HandlebarsViewEngine Class

HandlebarsViewEngine Class
An ASP.NET MVC ViewEngine that uses the Handlebars syntax for its view files.
Inheritance Hierarchy
SystemObject
HandlebarsDotNet.MvcHandlebarsViewEngine

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public class HandlebarsViewEngine : IViewEngine
Public Class HandlebarsViewEngine
    Implements IViewEngine
public ref class HandlebarsViewEngine : IViewEngine
type HandlebarsViewEngine =
    class
        interface IViewEngine
    end

The HandlebarsViewEngine type exposes the following members.

Constructors
 | Name | Description
Public method | HandlebarsViewEngine | Initializes a new instance of the HandlebarsViewEngine class with DefaultPathsProvider as its path provider.
Public method | HandlebarsViewEngine(IPathsProvider) | Initializes a new instance of the HandlebarsViewEngine class.
Top
Methods
 | Name | Description
Public method | ClearCache | Clears the cache used by HandlebarsViewEngine.
Protected method | CreateView | Creates an IView instance that is ready to be rendered.
 | ExtractActionName | Gets the action name from the controller context.
 | ExtractAreaName | Gets the area name from the controller context.
 | ExtractControllerName | Gets the controller name from the controller context.
Protected method | FileExists | Checks for file existence.
Public method | FindPartialView | Finds the specified partial view by using the specified controller context.
Public method | FindView | Finds the specified view by using the specified controller context.
Protected method | GetCacheKey | Gets the cachekey for the specified path.
Public method | RegisterHelper(String, HandlebarsBlockHelper) | Registers a block helper in this view engine's global configuration.
 | RegisterHelper(String, HandlebarsHelper) | Registers a helper in this view engine's global configuration.
Public method | RegisterMvcHelpers | Registers the builtin helpers that act a lot like their Razor/WebForms counterpart site-wide in the HandlebarsConfiguration.
Public method | RegisterSectionsHelpers | Registers the builtin helpers that act a lot like their Razor counterpart site-wide in the HandlebarsConfiguration.
Public method | RegisterTemplate | Registers a template in this view engine's global configuration.
Public method | ReleaseView | Releases the specified view by using the specified controller context.
Top
Properties
 | Name | Description
Public property | CacheKeyPrefix | The prefix to use when creating the cache keys.
Public property | HandlebarsConfiguration | A copy of this will be used when compiling the views. This is the place to provide site-wide helpers, block-helpers and templates.
Public property | Logger | The logger used. The default is a NullLogger instance.
Public property | PathsProvider | The paths provider used. The default is DefaultPathsProvider that mostly mimics the view files placements in the built-in MVC framework.
Public property | ViewExtension | The file extension the view files and partials must have in order for this ViewEngine to handle it. Default: ".hbs"
Public property | ViewsSlidingCacheTime | The length of time that compiled views are cached after last access. Set this to to disable caching. Default is 5 minutes.
Protected property | VirtualPathProvider | The VirtualPathProvider to use. This is only to facilitate unit testing! The default is the registered VirtualPathProvider.
Top
See Also

Reference

HandlebarsDotNet.Mvc Namespace


HandlebarsViewEngine Constructor

HandlebarsViewEngine Constructor
Overload List
 | Name | Description
Public method | HandlebarsViewEngine | Initializes a new instance of the HandlebarsViewEngine class with DefaultPathsProvider as its path provider.
Public method | HandlebarsViewEngine(IPathsProvider) | Initializes a new instance of the HandlebarsViewEngine class.
Top
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine Constructor

HandlebarsViewEngine Constructor
Initializes a new instance of the HandlebarsViewEngine class with DefaultPathsProvider as its path provider.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public HandlebarsViewEngine()
Public Sub New
public:
HandlebarsViewEngine()
new : unit -> HandlebarsViewEngine
See Also

Reference

HandlebarsViewEngine Class
HandlebarsViewEngine Overload


HandlebarsViewEngine Constructor (IPathsProvider)

HandlebarsViewEngine Constructor (IPathsProvider)
Initializes a new instance of the HandlebarsViewEngine class.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public HandlebarsViewEngine(
    IPathsProvider pathsProvider
)
Public Sub New (
    pathsProvider As IPathsProvider
)
public:
HandlebarsViewEngine(
    IPathsProvider^ pathsProvider
)
new :
        pathsProvider : IPathsProvider -> HandlebarsViewEngine

Parameters

pathsProvider
Type: HandlebarsDotNet.MvcIPathsProvider
The paths provider.
See Also

Reference

HandlebarsViewEngine Class
HandlebarsViewEngine Overload


HandlebarsViewEngine Methods

HandlebarsViewEngine Methods

The HandlebarsViewEngine type exposes the following members.

Methods
 | Name | Description
Public method | ClearCache | Clears the cache used by HandlebarsViewEngine.
Protected method | CreateView | Creates an IView instance that is ready to be rendered.
 | ExtractActionName | Gets the action name from the controller context.
 | ExtractAreaName | Gets the area name from the controller context.
 | ExtractControllerName | Gets the controller name from the controller context.
Protected method | FileExists | Checks for file existence.
Public method | FindPartialView | Finds the specified partial view by using the specified controller context.
Public method | FindView | Finds the specified view by using the specified controller context.
Protected method | GetCacheKey | Gets the cachekey for the specified path.
Public method | RegisterHelper(String, HandlebarsBlockHelper) | Registers a block helper in this view engine's global configuration.
 | RegisterHelper(String, HandlebarsHelper) | Registers a helper in this view engine's global configuration.
Public method | RegisterMvcHelpers | Registers the builtin helpers that act a lot like their Razor/WebForms counterpart site-wide in the HandlebarsConfiguration.
Public method | RegisterSectionsHelpers | Registers the builtin helpers that act a lot like their Razor counterpart site-wide in the HandlebarsConfiguration.
Public method | RegisterTemplate | Registers a template in this view engine's global configuration.
Public method | ReleaseView | Releases the specified view by using the specified controller context.
Top
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.ClearCache Method

HandlebarsViewEngineClearCache Method
Clears the cache used by HandlebarsViewEngine.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual void ClearCache(
    ControllerContext controllerContext
)
Public Overridable Sub ClearCache (
    controllerContext As ControllerContext
)
public:
virtual void ClearCache(
    ControllerContext^ controllerContext
)
abstract ClearCache :
        controllerContext : ControllerContext -> unit
override ClearCache :
        controllerContext : ControllerContext -> unit

Parameters

controllerContext
Type: ControllerContext
The controller context.
Remarks
If the HandlebarsConfiguration is changed after this HandlebarsViewEngine was added to Engines this need to be called.
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.CreateView Method

HandlebarsViewEngineCreateView Method
Creates an IView instance that is ready to be rendered.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
protected virtual IView CreateView(
    ControllerContext controllerContext,
    CompiledView compiledView,
    CompiledView[] layouts
)
Protected Overridable Function CreateView (
    controllerContext As ControllerContext,
    compiledView As CompiledView,
    layouts As CompiledView()
) As IView
protected:
virtual IView^ CreateView(
    ControllerContext^ controllerContext,
    CompiledView^ compiledView,
    array<CompiledView^>^ layouts
)
abstract CreateView :
        controllerContext : ControllerContext *
        compiledView : CompiledView *
        layouts : CompiledView[] -> IView
override CreateView :
        controllerContext : ControllerContext *
        compiledView : CompiledView *
        layouts : CompiledView[] -> IView

Parameters

controllerContext
Type: ControllerContext
The controller context.
compiledView
Type: HandlebarsDotNet.MvcCompiledView
The compiled view. The compiledView.Layout property is not used.
layouts
Type: HandlebarsDotNet.MvcCompiledView
The compiled layouts that will surround the view.

Return Value

Type: IView
An IView instance.
Remarks
The default implementation simply creates a HandlebarsView using the arguments provided.
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.ExtractActionName Method

HandlebarsViewEngineExtractActionName Method
Gets the action name from the controller context.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static string ExtractActionName(
    ControllerContext controllerContext
)
Public Shared Function ExtractActionName (
    controllerContext As ControllerContext
) As String
public:
static String^ ExtractActionName(
    ControllerContext^ controllerContext
)
static member ExtractActionName :
        controllerContext : ControllerContext -> string

Parameters

controllerContext
Type: ControllerContext
The controller context.

Return Value

Type: String
The action name.
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.ExtractAreaName Method

HandlebarsViewEngineExtractAreaName Method
Gets the area name from the controller context.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static string ExtractAreaName(
    ControllerContext controllerContext
)
Public Shared Function ExtractAreaName (
    controllerContext As ControllerContext
) As String
public:
static String^ ExtractAreaName(
    ControllerContext^ controllerContext
)
static member ExtractAreaName :
        controllerContext : ControllerContext -> string

Parameters

controllerContext
Type: ControllerContext
The controller context.

Return Value

Type: String
The area name, or if not within an area.
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.ExtractControllerName Method

HandlebarsViewEngineExtractControllerName Method
Gets the controller name from the controller context.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static string ExtractControllerName(
    ControllerContext controllerContext
)
Public Shared Function ExtractControllerName (
    controllerContext As ControllerContext
) As String
public:
static String^ ExtractControllerName(
    ControllerContext^ controllerContext
)
static member ExtractControllerName :
        controllerContext : ControllerContext -> string

Parameters

controllerContext
Type: ControllerContext
The controller context.

Return Value

Type: String
The controller name.
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.FileExists Method

HandlebarsViewEngineFileExists Method
Checks for file existence.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
protected virtual bool FileExists(
    ControllerContext controllerContext,
    string virtualPath
)
Protected Overridable Function FileExists (
    controllerContext As ControllerContext,
    virtualPath As String
) As Boolean
protected:
virtual bool FileExists(
    ControllerContext^ controllerContext,
    String^ virtualPath
)
abstract FileExists :
        controllerContext : ControllerContext *
        virtualPath : string -> bool
override FileExists :
        controllerContext : ControllerContext *
        virtualPath : string -> bool

Parameters

controllerContext
Type: ControllerContext
The controller context.
virtualPath
Type: SystemString
The path to check the existence for.

Return Value

Type: Boolean
if the file exists, if it doesn't.
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.FindPartialView Method

HandlebarsViewEngineFindPartialView Method
Finds the specified partial view by using the specified controller context.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual ViewEngineResult FindPartialView(
    ControllerContext controllerContext,
    string partialViewName,
    bool useCache
)
Public Overridable Function FindPartialView (
    controllerContext As ControllerContext,
    partialViewName As String,
    useCache As Boolean
) As ViewEngineResult
public:
virtual ViewEngineResult^ FindPartialView(
    ControllerContext^ controllerContext,
    String^ partialViewName,
    bool useCache
)
abstract FindPartialView :
        controllerContext : ControllerContext *
        partialViewName : string *
        useCache : bool -> ViewEngineResult
override FindPartialView :
        controllerContext : ControllerContext *
        partialViewName : string *
        useCache : bool -> ViewEngineResult

Parameters

controllerContext
Type: ControllerContext
The controller context.
partialViewName
Type: SystemString
The name of the partial view.
useCache
Type: SystemBoolean
to specify that the view engine returns the cached view, if a cached view exists; otherwise, .

Return Value

Type: ViewEngineResult
The partial view.

Implements

IViewEngine.FindPartialView(ControllerContext, String, Boolean)
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.FindView Method

HandlebarsViewEngineFindView Method
Finds the specified view by using the specified controller context.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual ViewEngineResult FindView(
    ControllerContext controllerContext,
    string viewName,
    string masterName,
    bool useCache
)
Public Overridable Function FindView (
    controllerContext As ControllerContext,
    viewName As String,
    masterName As String,
    useCache As Boolean
) As ViewEngineResult
public:
virtual ViewEngineResult^ FindView(
    ControllerContext^ controllerContext,
    String^ viewName,
    String^ masterName,
    bool useCache
)
abstract FindView :
        controllerContext : ControllerContext *
        viewName : string *
        masterName : string *
        useCache : bool -> ViewEngineResult
override FindView :
        controllerContext : ControllerContext *
        viewName : string *
        masterName : string *
        useCache : bool -> ViewEngineResult

Parameters

controllerContext
Type: ControllerContext
The controller context.
viewName
Type: SystemString
The name of the view.
masterName
Type: SystemString
The name of the master (layout).
useCache
Type: SystemBoolean
to specify that the view engine returns the cached view, if a cached view exists; otherwise, .

Return Value

Type: ViewEngineResult
The page view.

Implements

IViewEngine.FindView(ControllerContext, String, String, Boolean)
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.GetCacheKey Method

HandlebarsViewEngineGetCacheKey Method
Gets the cachekey for the specified path.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
protected virtual string GetCacheKey(
    ControllerContext controllerContext,
    string path
)
Protected Overridable Function GetCacheKey (
    controllerContext As ControllerContext,
    path As String
) As String
protected:
virtual String^ GetCacheKey(
    ControllerContext^ controllerContext,
    String^ path
)
abstract GetCacheKey :
        controllerContext : ControllerContext *
        path : string -> string
override GetCacheKey :
        controllerContext : ControllerContext *
        path : string -> string

Parameters

controllerContext
Type: ControllerContext
The controller context.
path
Type: SystemString
The path to create the cachekey for, usually in the form "~/Views/Home/Index.hbs". Can also be either of two (currently) special values: "global" for the global cachekey, and "config" for the cachekey used for this combination of area+controller.

Return Value

Type: String
The cache key to use for the specified path.
Remarks
This can be overridden in a subclass to for example provide tenant-specific cachekeys.
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.RegisterHelper Method

HandlebarsViewEngineRegisterHelper Method
Overload List
 | Name | Description
Public method | RegisterHelper(String, HandlebarsBlockHelper) | Registers a block helper in this view engine's global configuration.
 | RegisterHelper(String, HandlebarsHelper) | Registers a helper in this view engine's global configuration.
Top
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.RegisterHelper Method (String, HandlebarsBlockHelper)

HandlebarsViewEngineRegisterHelper Method (String, HandlebarsBlockHelper)
Registers a block helper in this view engine's global configuration.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual void RegisterHelper(
    string helperName,
    HandlebarsBlockHelper helperFunction
)
Public Overridable Sub RegisterHelper (
    helperName As String,
    helperFunction As HandlebarsBlockHelper
)
public:
virtual void RegisterHelper(
    String^ helperName,
    HandlebarsBlockHelper^ helperFunction
)
abstract RegisterHelper :
        helperName : string *
        helperFunction : HandlebarsBlockHelper -> unit
override RegisterHelper :
        helperName : string *
        helperFunction : HandlebarsBlockHelper -> unit

Parameters

helperName
Type: SystemString
The name of the block helper.
helperFunction
Type: HandlebarsBlockHelper
The function body for this helper.
Remarks
If you call this after the view engine has been registered, you need to call the ClearCache(ControllerContext) method.
See Also

Reference

HandlebarsViewEngine Class
RegisterHelper Overload


HandlebarsViewEngine.RegisterHelper Method (String, HandlebarsHelper)

HandlebarsViewEngineRegisterHelper Method (String, HandlebarsHelper)
Registers a helper in this view engine's global configuration.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual void RegisterHelper(
    string helperName,
    HandlebarsHelper helperFunction
)
Public Overridable Sub RegisterHelper (
    helperName As String,
    helperFunction As HandlebarsHelper
)
public:
virtual void RegisterHelper(
    String^ helperName,
    HandlebarsHelper^ helperFunction
)
abstract RegisterHelper :
        helperName : string *
        helperFunction : HandlebarsHelper -> unit
override RegisterHelper :
        helperName : string *
        helperFunction : HandlebarsHelper -> unit

Parameters

helperName
Type: SystemString
The name of the helper.
helperFunction
Type: HandlebarsHelper
The function body for this helper.
Remarks
If you call this after the view engine has been registered, you need to call the ClearCache(ControllerContext) method.
Examples
C#
Copy
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("link_to", (writer, context, parameters) => {
  writer.WriteSafeString("<a href='" + context.url + "'>" + context.text + "</a>");
});
controller
Copy
public ActionResult Index()
{
    var data = new {
        url = "https://github.com/rexm/handlebars.net",
        text = "Handlebars.Net"
    };
    return View(data);
}
view.hbs
Copy
Click here: {{link_to}}
Renders
Copy
Click here: <a href='https://github.com/rexm/handlebars.net'>Handlebars.Net</a>
See Also

Reference

HandlebarsViewEngine Class
RegisterHelper Overload


HandlebarsViewEngine.RegisterMvcHelpers Method

HandlebarsViewEngineRegisterMvcHelpers Method
Registers the builtin helpers that act a lot like their Razor/WebForms counterpart site-wide in the HandlebarsConfiguration.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual void RegisterMvcHelpers()
Public Overridable Sub RegisterMvcHelpers
public:
virtual void RegisterMvcHelpers()
abstract RegisterMvcHelpers : unit -> unit
override RegisterMvcHelpers : unit -> unit
Remarks
These are the ones registered if this is called.

From the Url namespace

  • url_action - Generates a fully qualified URL to an action method.
  • url_content - Converts a virtual (relative) path to an application absolute path and renders the result.
  • url_encode - Encodes text so it is usable in a URL.
From the Html namespace:
  • html_antiforgerytoken - Generates a hidden form field (anti-forgery token) that is validated when the form is submitted.
  • html_renderaction - Invokes the child action method using the specified parameters and renders the result inline in the parent view.
The ones related to bundling:
  • styles_render - Renders a link-tag to a stylesheet bundle
  • scripts_render - Renders a script-tag to a javascript bundle
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.RegisterSectionsHelpers Method

HandlebarsViewEngineRegisterSectionsHelpers Method
Registers the builtin helpers that act a lot like their Razor counterpart site-wide in the HandlebarsConfiguration.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual void RegisterSectionsHelpers()
Public Overridable Sub RegisterSectionsHelpers
public:
virtual void RegisterSectionsHelpers()
abstract RegisterSectionsHelpers : unit -> unit
override RegisterSectionsHelpers : unit -> unit
Remarks
These are the ones registered if this is called:

  • definesection - Assigns content to a named section.
  • issectiondefined - Returns a value to be used within an #if subexpression whether a section name has been defined.
  • rendersection - Renders the named section.
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.RegisterTemplate Method

HandlebarsViewEngineRegisterTemplate Method
Registers a template in this view engine's global configuration.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual void RegisterTemplate(
    string templateName,
    Action<TextWriter, Object> templateBody
)
Public Overridable Sub RegisterTemplate (
    templateName As String,
    templateBody As Action(Of TextWriter, Object)
)
public:
virtual void RegisterTemplate(
    String^ templateName,
    Action<TextWriter^, Object^>^ templateBody
)
abstract RegisterTemplate :
        templateName : string *
        templateBody : Action<TextWriter, Object> -> unit
override RegisterTemplate :
        templateName : string *
        templateBody : Action<TextWriter, Object> -> unit

Parameters

templateName
Type: SystemString
The name of the template.
templateBody
Type: SystemAction TextWriter, Object
The template action body.
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.ReleaseView Method

HandlebarsViewEngineReleaseView Method
Releases the specified view by using the specified controller context.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual void ReleaseView(
    ControllerContext controllerContext,
    IView view
)
Public Overridable Sub ReleaseView (
    controllerContext As ControllerContext,
    view As IView
)
public:
virtual void ReleaseView(
    ControllerContext^ controllerContext,
    IView^ view
)
abstract ReleaseView :
        controllerContext : ControllerContext *
        view : IView -> unit
override ReleaseView :
        controllerContext : ControllerContext *
        view : IView -> unit

Parameters

controllerContext
Type: ControllerContext
The controller context.
view
Type: IView
The view.

Implements

IViewEngine.ReleaseView(ControllerContext, IView)
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine Properties

HandlebarsViewEngine Properties

The HandlebarsViewEngine type exposes the following members.

Properties
 | Name | Description
Public property | CacheKeyPrefix | The prefix to use when creating the cache keys.
Public property | HandlebarsConfiguration | A copy of this will be used when compiling the views. This is the place to provide site-wide helpers, block-helpers and templates.
Public property | Logger | The logger used. The default is a NullLogger instance.
Public property | PathsProvider | The paths provider used. The default is DefaultPathsProvider that mostly mimics the view files placements in the built-in MVC framework.
Public property | ViewExtension | The file extension the view files and partials must have in order for this ViewEngine to handle it. Default: ".hbs"
Public property | ViewsSlidingCacheTime | The length of time that compiled views are cached after last access. Set this to to disable caching. Default is 5 minutes.
Protected property | VirtualPathProvider | The VirtualPathProvider to use. This is only to facilitate unit testing! The default is the registered VirtualPathProvider.
Top
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.CacheKeyPrefix Property

HandlebarsViewEngineCacheKeyPrefix Property
The prefix to use when creating the cache keys.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual string CacheKeyPrefix { get; set; }
Public Overridable Property CacheKeyPrefix As String
    Get
    Set
public:
virtual property String^ CacheKeyPrefix {
    String^ get ();
    void set (String^ value);
}
abstract CacheKeyPrefix : string with get, set
override CacheKeyPrefix : string with get, set

Property Value

Type: String
Remarks
If you against all odds need to register multiple instances of HandlebarsViewEngine in Engines then each instance must have its own unique CacheKeyPrefix.
The default prefix is a random value so usually this doesn't need to be set explicitly.
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.HandlebarsConfiguration Property

HandlebarsViewEngineHandlebarsConfiguration Property
A copy of this will be used when compiling the views. This is the place to provide site-wide helpers, block-helpers and templates.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual HandlebarsConfiguration HandlebarsConfiguration { get; protected set; }
Public Overridable Property HandlebarsConfiguration As HandlebarsConfiguration
    Get
    Protected Set
public:
virtual property HandlebarsConfiguration^ HandlebarsConfiguration {
    HandlebarsConfiguration^ get ();
    protected: void set (HandlebarsConfiguration^ value);
}
abstract HandlebarsConfiguration : HandlebarsConfiguration with get, set
override HandlebarsConfiguration : HandlebarsConfiguration with get, set

Property Value

Type: HandlebarsConfiguration
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.Logger Property

HandlebarsViewEngineLogger Property
The logger used. The default is a NullLogger instance.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual ILogger Logger { get; set; }
Public Overridable Property Logger As ILogger
    Get
    Set
public:
virtual property ILogger^ Logger {
    ILogger^ get ();
    void set (ILogger^ value);
}
abstract Logger : ILogger with get, set
override Logger : ILogger with get, set

Property Value

Type: ILogger
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.PathsProvider Property

HandlebarsViewEnginePathsProvider Property
The paths provider used. The default is DefaultPathsProvider that mostly mimics the view files placements in the built-in MVC framework.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public IPathsProvider PathsProvider { get; }
Public ReadOnly Property PathsProvider As IPathsProvider
    Get
public:
property IPathsProvider^ PathsProvider {
    IPathsProvider^ get ();
}
member PathsProvider : IPathsProvider with get

Property Value

Type: IPathsProvider
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.ViewExtension Property

HandlebarsViewEngineViewExtension Property
The file extension the view files and partials must have in order for this ViewEngine to handle it. Default: ".hbs"

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual string ViewExtension { get; set; }
Public Overridable Property ViewExtension As String
    Get
    Set
public:
virtual property String^ ViewExtension {
    String^ get ();
    void set (String^ value);
}
abstract ViewExtension : string with get, set
override ViewExtension : string with get, set

Property Value

Type: String
Remarks
Please note this should include the dot (contrary to VirtualPathProviderViewEngine).
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.ViewsSlidingCacheTime Property

HandlebarsViewEngineViewsSlidingCacheTime Property
The length of time that compiled views are cached after last access. Set this to to disable caching. Default is 5 minutes.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public virtual TimeSpan ViewsSlidingCacheTime { get; set; }
Public Overridable Property ViewsSlidingCacheTime As TimeSpan
    Get
    Set
public:
virtual property TimeSpan ViewsSlidingCacheTime {
    TimeSpan get ();
    void set (TimeSpan value);
}
abstract ViewsSlidingCacheTime : TimeSpan with get, set
override ViewsSlidingCacheTime : TimeSpan with get, set

Property Value

Type: TimeSpan
Remarks
If the VirtualPathProvider supports cache dependencies then an update to the source file will force a recompilation of the view.
See Also

Reference

HandlebarsViewEngine Class


HandlebarsViewEngine.VirtualPathProvider Property

HandlebarsViewEngineVirtualPathProvider Property
The VirtualPathProvider to use. This is only to facilitate unit testing! The default is the registered VirtualPathProvider.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
protected VirtualPathProvider VirtualPathProvider { get; }
Protected ReadOnly Property VirtualPathProvider As VirtualPathProvider
    Get
protected:
property VirtualPathProvider^ VirtualPathProvider {
    VirtualPathProvider^ get ();
}
member VirtualPathProvider : VirtualPathProvider with get

Property Value

Type: VirtualPathProvider
See Also

Reference

HandlebarsViewEngine Class


HelperException Class

HelperException Class
Represents the exception that is thrown for a HandlebarsDotNet.Mvc helper.
Inheritance Hierarchy
SystemObject
SystemException
HandlebarsDotNet.MvcHelperException

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
[SerializableAttribute]
public class HelperException : Exception
<SerializableAttribute>
Public Class HelperException
    Inherits Exception
[SerializableAttribute]
public ref class HelperException : public Exception
[<SerializableAttribute>]
type HelperException =
    class
        inherit Exception
    end
Constructors
 | Name | Description
Public method | HelperException | Initializes a new instance of the HelperException class.
Public method | HelperException(String) | Initializes a new instance of the HelperException class with a specified error message.
Protected method | HelperException(SerializationInfo, StreamingContext) | Initializes a new instance of the HelperException class with serialized data.
Public method | HelperException(String, Exception) | Initializes a new instance of the HelperException class with a specified error message and a reference to the inner exception that is the cause of this exception.
Top
Remarks
This exception is for example thrown for required arguments to the helper (like a path wasn't specified in a view file) but not for the arguments to the function that is part of the infrastructure for HandlebarsDotNet helpers (for example the TextWriter is ).
See Also

Reference

HandlebarsDotNet.Mvc Namespace


HelperException Constructor

HelperException Constructor
Overload List
 | Name | Description
Public method | HelperException | Initializes a new instance of the HelperException class.
Public method | HelperException(String) | Initializes a new instance of the HelperException class with a specified error message.
Protected method | HelperException(SerializationInfo, StreamingContext) | Initializes a new instance of the HelperException class with serialized data.
Public method | HelperException(String, Exception) | Initializes a new instance of the HelperException class with a specified error message and a reference to the inner exception that is the cause of this exception.
Top
See Also

Reference

HelperException Class


HelperException Constructor

HelperException Constructor
Initializes a new instance of the HelperException class.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public HelperException()
Public Sub New
public:
HelperException()
new : unit -> HelperException
See Also

Reference

HelperException Class
HelperException Overload


HelperException Constructor (String)

HelperException Constructor (String)
Initializes a new instance of the HelperException class with a specified error message.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public HelperException(
    string message
)
Public Sub New (
    message As String
)
public:
HelperException(
    String^ message
)
new :
        message : string -> HelperException

Parameters

message
Type: SystemString
The error message that explains the reason for the exception.
See Also

Reference

HelperException Class
HelperException Overload


HelperException Constructor (SerializationInfo, StreamingContext)

HelperException Constructor (SerializationInfo, StreamingContext)
Initializes a new instance of the HelperException class with serialized data.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
protected HelperException(
    SerializationInfo info,
    StreamingContext context
)
Protected Sub New (
    info As SerializationInfo,
    context As StreamingContext
)
protected:
HelperException(
    SerializationInfo^ info,
    StreamingContext context
)
new :
        info : SerializationInfo *
        context : StreamingContext -> HelperException

Parameters

info
Type: System.Runtime.SerializationSerializationInfo
The SerializationInfo that holds the serialized object data about the exception being thrown.
context
Type: System.Runtime.SerializationStreamingContext
The StreamingContext that contains contextual information about the source or destination.
See Also

Reference

HelperException Class
HelperException Overload


HelperException Constructor (String, Exception)

HelperException Constructor (String, Exception)
Initializes a new instance of the HelperException class with a specified error message and a reference to the inner exception that is the cause of this exception.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public HelperException(
    string message,
    Exception innerException
)
Public Sub New (
    message As String,
    innerException As Exception
)
public:
HelperException(
    String^ message,
    Exception^ innerException
)
new :
        message : string *
        innerException : Exception -> HelperException

Parameters

message
Type: SystemString
The error message that explains the reason for the exception.
innerException
Type: SystemException
The exception that is the cause of the current exception, or if no inner exception is specified.
See Also

Reference

HelperException Class
HelperException Overload


Helpers Class

Helpers Class
This class contains several useful Handlebars helpers that can be registered in the configuration.
Inheritance Hierarchy
SystemObject
HandlebarsDotNet.MvcHelpers

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static class Helpers
Public NotInheritable Class Helpers
public ref class Helpers abstract sealed
[<AbstractClassAttribute>]
[<SealedAttribute>]
type Helpers =  class end

The Helpers type exposes the following members.

Methods
Name | Description
DefineSection | Assigns content to a named section.
HtmlAntiForgeryToken | Generates a hidden form field (anti-forgery token) that is validated when the form is submitted.
HtmlRenderAction | Invokes the child action method using the specified parameters and renders the result inline in the parent view.
IsSectionDefined | Returns a value to be used within an #if subexpression whether a section name has been defined.
RenderSection | Renders the named section.
ScriptsRender | Renders script tags for the specified paths.
StylesRender | Renders link tags for a set of paths.
UrlAction | Generates a fully qualified URL to an action method.
UrlContent | Converts a virtual (relative) path to an application absolute path and renders the result.
UrlEncode | Encodes text so it is usable in a URL.
Top
See Also

Reference

HandlebarsDotNet.Mvc Namespace


Helpers Methods

Helpers Methods

The Helpers type exposes the following members.

Methods
Name | Description
DefineSection | Assigns content to a named section.
HtmlAntiForgeryToken | Generates a hidden form field (anti-forgery token) that is validated when the form is submitted.
HtmlRenderAction | Invokes the child action method using the specified parameters and renders the result inline in the parent view.
IsSectionDefined | Returns a value to be used within an #if subexpression whether a section name has been defined.
RenderSection | Renders the named section.
ScriptsRender | Renders script tags for the specified paths.
StylesRender | Renders link tags for a set of paths.
UrlAction | Generates a fully qualified URL to an action method.
UrlContent | Converts a virtual (relative) path to an application absolute path and renders the result.
UrlEncode | Encodes text so it is usable in a URL.
Top
See Also

Reference

Helpers Class


Helpers.DefineSection Method

HelpersDefineSection Method
Assigns content to a named section.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static void DefineSection(
    TextWriter writer,
    HelperOptions options,
    Object context,
    params Object[] arguments
)
Public Shared Sub DefineSection (
    writer As TextWriter,
    options As HelperOptions,
    context As Object,
    ParamArray arguments As Object()
)
public:
static void DefineSection(
    TextWriter^ writer,
    HelperOptions^ options,
    Object^ context,
    ... array<Object^>^ arguments
)
static member DefineSection :
        writer : TextWriter *
        options : HelperOptions *
        context : Object *
        arguments : Object[] -> unit

Parameters

writer
Type: System.IOTextWriter
The TextWriter provided by HandlebarsDotNet
options
Type: HelperOptions
The HelperOptions provided by HandlebarsDotNet
context
Type: SystemObject
The context (model) provided by HandlebarsDotNet
arguments
Type: SystemObject
The arguments from the view, provided by HandlebarsDotNet
Remarks
This helper is among the ones registered if RegisterSectionsHelpers is called. If so, it is registered as definesection but you can choose your own name for this:
C#
Copy
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("definesection", HandlebarsDotNet.Mvc.Helpers.DefineSection);
It works like Razor's @section statement. For a nice write-up, see https://weblogs.asp.net/scottgu/asp-net-mvc-3-layouts-and-sections-with-razor.

Usage

{{#definesection [name] [mode="replace"|"append"|"prepend"]}}
content here
{{/definesection}}

Arguments

name
string (required) - The name of the section.
mode
string (required) - The operation mode. Specifying mode is not required but if specified it must be one of three values: "replace" (default), "append" or "prepend".

Description

This helper allows splitting up the normal contigous HTML contents in view files so a section can be rendered at a specified location within a layout.
Normally the whole contents from the view is rendered by {{{body}}} in a layout file, but this helper takes it out of the normal flow so it can be rendered at the specified point by {{rendersection "..."}} in the layout.
See the example for how it can be used.

The mode attribute can take different values:

mode="replace"
This ignores any previously defined section with this name and just sets the contents. This is the default.
mode="append"
Appends the content to any previously defined section with this name.
mode="prepend"
Prepends the content to any previously defined section with this name.
For the append and prepend modes the named section doesn't have to be defined beforehand. In those cases it works as mode="replace".
Examples
view.hbs
Copy
{{!< default}}
{{#definesection "sidebar"}}
    For more info, see<br />
    <a href="link1.html">Link 1</a><br />
    <a href="link2.html">Link 2</a><br />
{{/definesection}}
~/Views/_Layouts/default.hbs
Copy
{{#if (issectiondefined "sidebar")}}
    <div id="sidebar">
        {{{rendersection "sidebar"}}}
    </div>
{{else}}
    <p>Default sidebar content...</p>
{{/if}}
See Also

Reference

Helpers Class


Helpers.HtmlAntiForgeryToken Method

HelpersHtmlAntiForgeryToken Method
Generates a hidden form field (anti-forgery token) that is validated when the form is submitted.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static void HtmlAntiForgeryToken(
    TextWriter writer,
    Object context,
    params Object[] arguments
)
Public Shared Sub HtmlAntiForgeryToken (
    writer As TextWriter,
    context As Object,
    ParamArray arguments As Object()
)
public:
static void HtmlAntiForgeryToken(
    TextWriter^ writer,
    Object^ context,
    ... array<Object^>^ arguments
)
static member HtmlAntiForgeryToken :
        writer : TextWriter *
        context : Object *
        arguments : Object[] -> unit

Parameters

writer
Type: System.IOTextWriter
The TextWriter provided by HandlebarsDotNet
context
Type: SystemObject
The context (model) provided by HandlebarsDotNet
arguments
Type: SystemObject
The arguments from the view, provided by HandlebarsDotNet
Remarks
This helper is among the ones registered if RegisterMvcHelpers is called. If so, it is registered as html_antiforgerytoken but you can choose your own name for this:
C#
Copy
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("html_antiforgerytoken", HandlebarsDotNet.Mvc.Helpers.HtmlAntiForgeryToken);
It works like https://msdn.microsoft.com/en-us/library/system.web.mvc.htmlhelper.antiforgerytoken.aspx.

Usage

{{html_antiforgerytoken}}

Arguments

(none)

Description

The anti-forgery token can be used to help protect your application against cross-site request forgery. To use this feature, render the anti-forgery token within a form and add the ValidateAntiForgeryTokenAttribute attribute to the action method that you want to protect.

For information about cross-site request forgery (CSRF) see https://docs.microsoft.com/en-us/aspnet/mvc/overview/security/xsrfcsrf-prevention-in-aspnet-mvc-and-web-pages.

The output is rendered with HandlebarsDotNet's WriteSafeString() meaning that using the triple-mustache is not needed.

Examples
This example assumes this helper has been registered as "html_antiforgerytoken".
view.hbs
Copy
{{html_antiforgerytoken}}
Renders
Copy
<input name="__RequestVerificationToken" type="hidden" value="UzCEoDwZ...(quite a long string)" />
See Also

Reference

Helpers Class


Helpers.HtmlRenderAction Method

HelpersHtmlRenderAction Method
Invokes the child action method using the specified parameters and renders the result inline in the parent view.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static void HtmlRenderAction(
    TextWriter writer,
    Object context,
    params Object[] arguments
)
Public Shared Sub HtmlRenderAction (
    writer As TextWriter,
    context As Object,
    ParamArray arguments As Object()
)
public:
static void HtmlRenderAction(
    TextWriter^ writer,
    Object^ context,
    ... array<Object^>^ arguments
)
static member HtmlRenderAction :
        writer : TextWriter *
        context : Object *
        arguments : Object[] -> unit

Parameters

writer
Type: System.IOTextWriter
The TextWriter provided by HandlebarsDotNet
context
Type: SystemObject
The context (model) provided by HandlebarsDotNet
arguments
Type: SystemObject
The arguments from the view, provided by HandlebarsDotNet
Remarks
This helper is among the ones registered if RegisterMvcHelpers is called. If so, it is registered as html_renderaction but you can choose your own name for this:
C#
Copy
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("html_renderaction", HandlebarsDotNet.Mvc.Helpers.HtmlRenderAction);
It works like https://msdn.microsoft.com/en-us/library/system.web.mvc.html.childactionextensions.renderaction.aspx.

Usage

{{html_renderaction [action] [controller] [key=value ...]}}

Arguments

action
string (required) - The name of the action.
controller
string (required) - The name of the controller (without "Controller").
attributes
(optional) - The rest of the attributes are used as route values.

Description

The output is rendered with HandlebarsDotNet's WriteSafeString() meaning that using the triple-mustache is not needed.

Examples
This example assumes this helper has been registered as "html_renderaction". Please note that the child action doesn't have to use the same view engine.
view.hbs
Copy
Intro text<br />
{{html_renderaction "Details" "Widget" id="SupDup"}}
WidgetController.cs
Copy
public WidgetController
{
    public ActionResult Details(string id)
    {
        var model = new WidgetModel
        {
            Id = id,
            Description = "Super duper widget!"
        };
        return PartialView(model);
    }
}
Details.cshtml
Copy
@model WidgetModel
<p>Id: @Model.Id</p>
<p>@Model.Description</p>
Renders
Copy
Intro text<br />
<p>Id: SupDup</p>
<p>Super duper widget!</p>
See Also

Reference

Helpers Class
HandlebarsDotNet.Mvc Namespace

Other Resources

https://msdn.microsoft.com/en-us/library/system.web.mvc.html.childactionextensions.renderaction.aspx


Helpers.IsSectionDefined Method

HelpersIsSectionDefined Method
Returns a value to be used within an #if subexpression whether a section name has been defined.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static void IsSectionDefined(
    TextWriter writer,
    Object context,
    params Object[] arguments
)
Public Shared Sub IsSectionDefined (
    writer As TextWriter,
    context As Object,
    ParamArray arguments As Object()
)
public:
static void IsSectionDefined(
    TextWriter^ writer,
    Object^ context,
    ... array<Object^>^ arguments
)
static member IsSectionDefined :
        writer : TextWriter *
        context : Object *
        arguments : Object[] -> unit

Parameters

writer
Type: System.IOTextWriter
The TextWriter provided by HandlebarsDotNet
context
Type: SystemObject
The context (model) provided by HandlebarsDotNet
arguments
Type: SystemObject
The arguments from the view, provided by HandlebarsDotNet
Remarks
This helper is among the ones registered if RegisterSectionsHelpers is called. If so, it is registered as issectiondefined but you can choose your own name for this:
C#
Copy
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("issectiondefined", HandlebarsDotNet.Mvc.Helpers.IsSectionDefined);
It works like Razor's IsSectionDefined method. For a nice write-up, see https://weblogs.asp.net/scottgu/asp-net-mvc-3-layouts-and-sections-with-razor.

Usage

{{#if (issectiondefined [name])}} ... {{/if}}

Arguments

name
string (required) - The name of the section.

Description

This helper checks if a named section has been defined, and returns a truthy value if so. That value can be used in an {{#if}}-test to for example render the section or default content as in the example below.
Examples
view.hbs
Copy
{{!< default}}
{{#definesection "sidebar"}}
    For more info, see<br />
    <a href="link1.html">Link 1</a><br />
    <a href="link2.html">Link 2</a><br />
{{/definesection}}
~/Views/_Layouts/default.hbs
Copy
{{#if (issectiondefined "sidebar")}}
    <div id="sidebar">
        {{{rendersection "sidebar"}}}
    </div>
{{else}}
    <p>Default sidebar content...</p>
{{/if}}
See Also

Reference

Helpers Class


Helpers.RenderSection Method

HelpersRenderSection Method
Renders the named section.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static void RenderSection(
    TextWriter writer,
    Object context,
    params Object[] arguments
)
Public Shared Sub RenderSection (
    writer As TextWriter,
    context As Object,
    ParamArray arguments As Object()
)
public:
static void RenderSection(
    TextWriter^ writer,
    Object^ context,
    ... array<Object^>^ arguments
)
static member RenderSection :
        writer : TextWriter *
        context : Object *
        arguments : Object[] -> unit

Parameters

writer
Type: System.IOTextWriter
The TextWriter provided by HandlebarsDotNet
context
Type: SystemObject
The context (model) provided by HandlebarsDotNet
arguments
Type: SystemObject
The arguments from the view, provided by HandlebarsDotNet
Remarks
This helper is among the ones registered if RegisterSectionsHelpers is called. If so, it is registered as rendersection but you can choose your own name for this:
C#
Copy
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("rendersection", HandlebarsDotNet.Mvc.Helpers.RenderSection);
It works like Razor's RenderSection method. For a nice write-up, see https://weblogs.asp.net/scottgu/asp-net-mvc-3-layouts-and-sections-with-razor.

Usage

{{rendersection [name] [required=true|false])}}

Arguments

name
string (required) - The name of the section.
required
bool (required) - Whether the section must have been defined. Specifying required is not required but if specified it must be true (default) or false.

Description

Renders a named section.
If the section hasn't been defined and required is (which it is by default) an exception is thrown.
If the section hasn't been defined and required is nothing is rendered.
If the section has been defined it is rendered HTML-escaped, unless you use the triple-mustache: {{{rendersection ...}}}.
Examples
view.hbs
Copy
{{!< default}}
{{#definesection "sidebar"}}
    For more info, see<br />
    <a href="link1.html">Link 1</a><br />
    <a href="link2.html">Link 2</a><br />
{{/definesection}}
~/Views/_Layouts/default.hbs
Copy
{{#if (issectiondefined "sidebar")}}
    <div id="sidebar">
        {{{rendersection "sidebar"}}}
    </div>
{{else}}
    <p>Default sidebar content...</p>
{{/if}}
See Also

Reference

Helpers Class


Helpers.ScriptsRender Method

HelpersScriptsRender Method
Renders script tags for the specified paths.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static void ScriptsRender(
    TextWriter writer,
    Object context,
    params Object[] arguments
)
Public Shared Sub ScriptsRender (
    writer As TextWriter,
    context As Object,
    ParamArray arguments As Object()
)
public:
static void ScriptsRender(
    TextWriter^ writer,
    Object^ context,
    ... array<Object^>^ arguments
)
static member ScriptsRender :
        writer : TextWriter *
        context : Object *
        arguments : Object[] -> unit

Parameters

writer
Type: System.IOTextWriter
The TextWriter provided by HandlebarsDotNet
context
Type: SystemObject
The context (model) provided by HandlebarsDotNet
arguments
Type: SystemObject
The arguments from the view, provided by HandlebarsDotNet
Remarks
This helper is among the ones registered if RegisterMvcHelpers is called. If so, it is registered as scripts_render but you can choose your own name for this:
C#
Copy
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("scripts_render", HandlebarsDotNet.Mvc.Helpers.ScriptsRender);
It works like https://msdn.microsoft.com/en-us/library/system.web.optimization.scripts.render.aspx.

Usage

{{scripts_render [path ...]}}

Arguments

string [path] (optional) - A set of virtual paths for which to generate script tags.

Description

This helper generates multiple script tags for each item in the bundle if EnableOptimizations is set to . When optimizations are enabled, it generates a single script tag to a version-stamped URL which represents the entire bundle.
See https://docs.microsoft.com/en-us/aspnet/mvc/overview/performance/bundling-and-minification for some general guidance about bundling.

The output is rendered with HandlebarsDotNet's WriteSafeString() meaning that using the triple-mustache is not needed.

Examples
This example assumes this helper has been registered as "scripts_render" and optimizations are enabled.
view.hbs
Copy
{{scripts_render "~/bundles/jquery"}}
Renders
Copy
<script src="/bundles/jquery?v=JzhfglzUfmVF2qo-weTo-kvXJ9AJvIRBLmu11PgpbVY1"></script>
See Also

Reference

Helpers Class


Helpers.StylesRender Method

HelpersStylesRender Method
Renders link tags for a set of paths.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static void StylesRender(
    TextWriter writer,
    Object context,
    params Object[] arguments
)
Public Shared Sub StylesRender (
    writer As TextWriter,
    context As Object,
    ParamArray arguments As Object()
)
public:
static void StylesRender(
    TextWriter^ writer,
    Object^ context,
    ... array<Object^>^ arguments
)
static member StylesRender :
        writer : TextWriter *
        context : Object *
        arguments : Object[] -> unit

Parameters

writer
Type: System.IOTextWriter
The TextWriter provided by HandlebarsDotNet
context
Type: SystemObject
The context (model) provided by HandlebarsDotNet
arguments
Type: SystemObject
The arguments from the view, provided by HandlebarsDotNet
Remarks
This helper is among the ones registered if RegisterMvcHelpers is called. If so, it is registered as styles_render but you can choose your own name for this:
C#
Copy
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("styles_render", HandlebarsDotNet.Mvc.Helpers.StylesRender);
It works like https://msdn.microsoft.com/en-us/library/system.web.optimization.styles.render.aspx.

Usage

{{styles_render [path ...]}}

Arguments

string [path] (optional) - A set of virtual paths for which to generate link tags.

Description

This helper generates multiple link tags for each item in the bundle if EnableOptimizations is set to . When optimizations are enabled, it generates a single link tag to a version-stamped URL which represents the entire bundle.
See https://docs.microsoft.com/en-us/aspnet/mvc/overview/performance/bundling-and-minification for some general guidance about bundling.

The output is rendered with HandlebarsDotNet's WriteSafeString() meaning that using the triple-mustache is not needed.

Examples
This example assumes this helper has been registered as "styles_render" and optimizations are enabled.
view.hbs
Copy
{{styles_render "~/Content/css"}}
Renders
Copy
<link href="/Content/css?v=WMr-pvK-ldSbNXHT-cT0d9QF2pqi7sqz_4MtKl04wlw1" rel="stylesheet"/>
See Also

Reference

Helpers Class


Helpers.UrlAction Method

HelpersUrlAction Method
Generates a fully qualified URL to an action method.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static void UrlAction(
    TextWriter writer,
    Object context,
    params Object[] arguments
)
Public Shared Sub UrlAction (
    writer As TextWriter,
    context As Object,
    ParamArray arguments As Object()
)
public:
static void UrlAction(
    TextWriter^ writer,
    Object^ context,
    ... array<Object^>^ arguments
)
static member UrlAction :
        writer : TextWriter *
        context : Object *
        arguments : Object[] -> unit

Parameters

writer
Type: System.IOTextWriter
The TextWriter provided by HandlebarsDotNet
context
Type: SystemObject
The context (model) provided by HandlebarsDotNet
arguments
Type: SystemObject
The arguments from the view, provided by HandlebarsDotNet
Remarks
This helper is among the ones registered if RegisterMvcHelpers is called. If so, it is registered as url_action but you can choose your own name for this:
C#
Copy
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("url_action", HandlebarsDotNet.Mvc.Helpers.UrlAction);
It works like https://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.action.aspx.

Usage

{{url_action [controller=...] [action=...] [protocol=...] [host=...] [fragment=...] [key=value ...]}}

Arguments

controller
string (optional) - The name of the controller (without "Controller").
action
string (optional) - The name of the action.
protocol
string (optional) - The protocol for the URL, such as "http" or "https".
host
string (optional) - The host name for the URL.
fragment
string (optional) - The "fragment" for the URL (a named anchor).
the rest
(optional) - The rest of the attributes are used as route values.

Description

This helper generates a URL from the routing table using the specified arguments.
The URL that is rendered has a format like the following:

/Home/About

If special characters in the URL must be encoded, use the url_encode helper. For the previous example, the url_encode helper renders the following string:

%2fHome%2fAbout
Examples
This example assumes this helper has been registered as "url_action", the application is installed in the web root, and that the default routes are used:
view.hbs
Copy
{{url_action controller="Home" action="Index"}}
{{url_action controller="Home" action="Contact" fragment="fragment" id="support" extra="greetings"}}
{{url_action controller="Account" action="Login"}}
{{url_encode (url_action controller="Account" action="Login")}}
Renders
Copy
/
/Home/Contact/support?extra=greetings#fragment
/Account/Login
%2fAccount%2fLogin
See Also

Reference

Helpers Class


Helpers.UrlContent Method

HelpersUrlContent Method
Converts a virtual (relative) path to an application absolute path and renders the result.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static void UrlContent(
    TextWriter writer,
    Object context,
    params Object[] arguments
)
Public Shared Sub UrlContent (
    writer As TextWriter,
    context As Object,
    ParamArray arguments As Object()
)
public:
static void UrlContent(
    TextWriter^ writer,
    Object^ context,
    ... array<Object^>^ arguments
)
static member UrlContent :
        writer : TextWriter *
        context : Object *
        arguments : Object[] -> unit

Parameters

writer
Type: System.IOTextWriter
The TextWriter provided by HandlebarsDotNet
context
Type: SystemObject
The context (model) provided by HandlebarsDotNet
arguments
Type: SystemObject
The arguments from the view, provided by HandlebarsDotNet
Remarks
This helper is among the ones registered if RegisterMvcHelpers is called. If so, it is registered as url_content but you can choose your own name for this:
C#
Copy
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("url_content", HandlebarsDotNet.Mvc.Helpers.UrlContent);
It works like https://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.content.aspx but with special cases (see below).

Usage

{{url_content [path]}}

Arguments

string [path] (required) - A virtual path

Description

This helper deviates from the one used in UrlHelper in the following ways:
If the path is exactly "~" it renders the path to the virtual directory (UrlHelper renders with an ending slash), and
if it starts with "~" but not "~/" it renders the path unchanged (UrlHelper generates an argument exception for this case).
If it does start with "~/" the path is converted to an application absolute path (just like the UrlHelper one) and rendered.
Just like the UrlHelper helper it renders the argument unchanged if it doesn't start with "~".

What this means is that if the path to this helper ends with a slash the rendered output will also do that.
If the path has the resemblance of a Linux user directory (~user) it will be unchanged, otherwise if it does start with "~" then the tilde is converted to the virtual directory where the web application is installed (usually the root "/").
If it doesn't start with "~" it will be rendered unchanged.

Examples
This example assumes this helper has been registered as "url_content" and the application is installed in the web root.
view.hbs
Copy
"~"             = {{url_content "~"}}
"~/"            = {{url_content "~/"}}
"~/favicon.ico" = {{url_content "~/favicon.ico"}}
"~user/"        = {{url_content "~user/"}}
Renders
Copy
"~"             =
"~/"            = /
"~/favicon.ico" = /favicon.ico
"~user/"        = ~user/
See Also

Reference

Helpers Class


Helpers.UrlEncode Method

HelpersUrlEncode Method
Encodes text so it is usable in a URL.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static void UrlEncode(
    TextWriter writer,
    Object context,
    params Object[] arguments
)
Public Shared Sub UrlEncode (
    writer As TextWriter,
    context As Object,
    ParamArray arguments As Object()
)
public:
static void UrlEncode(
    TextWriter^ writer,
    Object^ context,
    ... array<Object^>^ arguments
)
static member UrlEncode :
        writer : TextWriter *
        context : Object *
        arguments : Object[] -> unit

Parameters

writer
Type: System.IOTextWriter
The TextWriter provided by HandlebarsDotNet
context
Type: SystemObject
The context (model) provided by HandlebarsDotNet
arguments
Type: SystemObject
The arguments from the view, provided by HandlebarsDotNet
Remarks
This helper is among the ones registered if RegisterMvcHelpers is called. If so, it is registered as url_encode but you can choose your own name for this:
C#
Copy
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("url_encode", HandlebarsDotNet.Mvc.Helpers.UrlEncode);
It works like https://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.encode.aspx.

Usage

{{url_encode [str]}}

Arguments

string [str] (required) - The string to render URL encoded.

Description

Examples
This example assumes this helper has been registered as "url_encode".
view.hbs
Copy
{{url_encode "/Home/About"}}
Renders
Copy
%2fHome%2fAbout
See Also

Reference

Helpers Class


ILogger Interface

ILogger Interface
The interface used by HandlebarsViewEngine for logging purposes.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public interface ILogger
Public Interface ILogger
public interface class ILogger
type ILogger =  interface end

The ILogger type exposes the following members.

Methods
 | Name | Description
Public method | Log | Logs a message.
Public method | Trace | Logs a trace message.
Public method | Warn | Logs a warning message.
Top
Remarks
Having a "Func<string> messageGenerator" argument may look strange, but that is a performance optimization:
If the message isn't used (maybe the NullLogger is used for example), we don't have to pay the CPU cycles for generating the formatted string to be logged.
See Also

Reference

HandlebarsDotNet.Mvc Namespace


ILogger Methods

ILogger Methods

The ILogger type exposes the following members.

Methods
 | Name | Description
Public method | Log | Logs a message.
Public method | Trace | Logs a trace message.
Public method | Warn | Logs a warning message.
Top
See Also

Reference

ILogger Interface


ILogger.Log Method

ILoggerLog Method
Logs a message.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
void Log(
    LoggerCategory category,
    Func<string> messageGenerator
)
Sub Log (
    category As LoggerCategory,
    messageGenerator As Func(Of String)
)
void Log(
    LoggerCategory category,
    Func<String^>^ messageGenerator
)
abstract Log :
        category : LoggerCategory *
        messageGenerator : Func<string> -> unit

Parameters

category
Type: HandlebarsDotNet.MvcLoggerCategory
The category the message is used for.
messageGenerator
Type: SystemFunc String
See Also

Reference

ILogger Interface


ILogger.Trace Method

ILoggerTrace Method
Logs a trace message.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
void Trace(
    LoggerCategory category,
    Func<string> messageGenerator
)
Sub Trace (
    category As LoggerCategory,
    messageGenerator As Func(Of String)
)
void Trace(
    LoggerCategory category,
    Func<String^>^ messageGenerator
)
abstract Trace :
        category : LoggerCategory *
        messageGenerator : Func<string> -> unit

Parameters

category
Type: HandlebarsDotNet.MvcLoggerCategory
The category the message is used for.
messageGenerator
Type: SystemFunc String
See Also

Reference

ILogger Interface


ILogger.Warn Method

ILoggerWarn Method
Logs a warning message.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
void Warn(
    LoggerCategory category,
    Func<string> messageGenerator
)
Sub Warn (
    category As LoggerCategory,
    messageGenerator As Func(Of String)
)
void Warn(
    LoggerCategory category,
    Func<String^>^ messageGenerator
)
abstract Warn :
        category : LoggerCategory *
        messageGenerator : Func<string> -> unit

Parameters

category
Type: HandlebarsDotNet.MvcLoggerCategory
The category the message is used for.
messageGenerator
Type: SystemFunc String
See Also

Reference

ILogger Interface


IPathsProvider Interface

IPathsProvider Interface
The interface used by HandlebarsViewEngine when getting the different paths.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public interface IPathsProvider
Public Interface IPathsProvider
public interface class IPathsProvider
type IPathsProvider =  interface end

The IPathsProvider type exposes the following members.

Methods
 | Name | Description
Public method | GetLayoutFolders | Gets the folders for where the layout files can be for the given ControllerContext. The paths returned are in the form "~/Views/_Layouts/".
Public method | GetPartialsFolders | Gets the folders for where the partials files can be for the given ControllerContext. The paths returned are in the form "~/Views/_Partials/".
Public method | GetViewFolders | Gets the folders for where the view files can be for the given ControllerContext. The paths returned are in the form "~/Views/Home/".
Top
Remarks
Unless an implementation is provided when creating the HandlebarsViewEngine, the DefaultPathsProvider is used.
See Also

Reference

HandlebarsDotNet.Mvc Namespace


IPathsProvider Methods

IPathsProvider Methods

The IPathsProvider type exposes the following members.

Methods
 | Name | Description
Public method | GetLayoutFolders | Gets the folders for where the layout files can be for the given ControllerContext. The paths returned are in the form "~/Views/_Layouts/".
Public method | GetPartialsFolders | Gets the folders for where the partials files can be for the given ControllerContext. The paths returned are in the form "~/Views/_Partials/".
Public method | GetViewFolders | Gets the folders for where the view files can be for the given ControllerContext. The paths returned are in the form "~/Views/Home/".
Top
See Also

Reference

IPathsProvider Interface


IPathsProvider.GetLayoutFolders Method

IPathsProviderGetLayoutFolders Method
Gets the folders for where the layout files can be for the given ControllerContext. The paths returned are in the form "~/Views/_Layouts/".

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
IEnumerable<string> GetLayoutFolders(
    ControllerContext controllerContext
)
Function GetLayoutFolders (
    controllerContext As ControllerContext
) As IEnumerable(Of String)
IEnumerable<String^>^ GetLayoutFolders(
    ControllerContext^ controllerContext
)
abstract GetLayoutFolders :
        controllerContext : ControllerContext -> IEnumerable<string>

Parameters

controllerContext
Type: ControllerContext
The ControllerContext for the current request.

Return Value

Type: IEnumerable String
Returns an ordered IEnumerable<string> with the paths for HandlebarsViewEngine to check.
See Also

Reference

IPathsProvider Interface


IPathsProvider.GetPartialsFolders Method

IPathsProviderGetPartialsFolders Method
Gets the folders for where the partials files can be for the given ControllerContext. The paths returned are in the form "~/Views/_Partials/".

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
IEnumerable<string> GetPartialsFolders(
    ControllerContext controllerContext
)
Function GetPartialsFolders (
    controllerContext As ControllerContext
) As IEnumerable(Of String)
IEnumerable<String^>^ GetPartialsFolders(
    ControllerContext^ controllerContext
)
abstract GetPartialsFolders :
        controllerContext : ControllerContext -> IEnumerable<string>

Parameters

controllerContext
Type: ControllerContext
The ControllerContext for the current request.

Return Value

Type: IEnumerable String
Returns an ordered IEnumerable<string> with the paths for HandlebarsViewEngine to check.
See Also

Reference

IPathsProvider Interface


IPathsProvider.GetViewFolders Method

IPathsProviderGetViewFolders Method
Gets the folders for where the view files can be for the given ControllerContext. The paths returned are in the form "~/Views/Home/".

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
IEnumerable<string> GetViewFolders(
    ControllerContext controllerContext
)
Function GetViewFolders (
    controllerContext As ControllerContext
) As IEnumerable(Of String)
IEnumerable<String^>^ GetViewFolders(
    ControllerContext^ controllerContext
)
abstract GetViewFolders :
        controllerContext : ControllerContext -> IEnumerable<string>

Parameters

controllerContext
Type: ControllerContext
The ControllerContext for the current request.

Return Value

Type: IEnumerable String
Returns an ordered IEnumerable<string> with the paths for HandlebarsViewEngine to check.
See Also

Reference

IPathsProvider Interface


LoggerCategory Enumeration

LoggerCategory Enumeration
The different categories used for the logging component in HandlebarsViewEngine. These are the only ones (currently) used by it.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public enum LoggerCategory
Public Enumeration LoggerCategory
public enum class LoggerCategory
type LoggerCategory
Members
Member name | Value | Description
Api | 0 | Category Api is typically used with Trace(LoggerCategory, FuncString) just when a method has been entered or about to leave it.
Compile | 1 | Category Compile is used related to compiling a view, layout, etc.
Cache | 2 | Category Cache is used when something related to the caching is logged.
Examples
This is what the ClearCache(ControllerContext) method looks like (at one point in time at least):
C#
Copy
public virtual void ClearCache(ControllerContext controllerContext)
{
    if(controllerContext == null)
        throw new ArgumentNullException("controllerContext");

    Logger.Trace(LoggerCategory.Api, () => "ClearCache() called.");

    var globalCacheKey = GetCacheKey(controllerContext, STR_GLOBAL);

    Logger.Log(LoggerCategory.Cache, () => "Clearing the cache.");

    // Simply removing the global cachekey will remove all of it, due to the cache dependencies.
    Cache.Remove(globalCacheKey);
}
See Also

Reference

HandlebarsDotNet.Mvc Namespace


NullLogger Class

NullLogger Class
A logger that does nothing. This is the default logger for HandlebarsViewEngine.
Inheritance Hierarchy
SystemObject
HandlebarsDotNet.MvcNullLogger

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public class NullLogger : ILogger
Public Class NullLogger
    Implements ILogger
public ref class NullLogger : ILogger
type NullLogger =
    class
        interface ILogger
    end

The NullLogger type exposes the following members.

Constructors
 | Name | Description
Public method | NullLogger | Initializes a new instance of the NullLogger class
Top
Methods
 | Name | Description
Public method | Log | The NullLogger does nothing in this ILogger implementation.
Public method | Trace | The NullLogger does nothing in this ILogger implementation.
Public method | Warn | The NullLogger does nothing in this ILogger implementation.
Top
Properties
Name | Description
Instance | A singleton instance of NullLogger.
Top
See Also

Reference

HandlebarsDotNet.Mvc Namespace


NullLogger Constructor

NullLogger Constructor
Initializes a new instance of the NullLogger class

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public NullLogger()
Public Sub New
public:
NullLogger()
new : unit -> NullLogger
See Also

Reference

NullLogger Class


NullLogger Methods

NullLogger Methods

The NullLogger type exposes the following members.

Methods
 | Name | Description
Public method | Log | The NullLogger does nothing in this ILogger implementation.
Public method | Trace | The NullLogger does nothing in this ILogger implementation.
Public method | Warn | The NullLogger does nothing in this ILogger implementation.
Top
See Also

Reference

NullLogger Class


NullLogger.Log Method

NullLoggerLog Method
The NullLogger does nothing in this ILogger implementation.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public void Log(
    LoggerCategory category,
    Func<string> messageGenerator
)
Public Sub Log (
    category As LoggerCategory,
    messageGenerator As Func(Of String)
)
public:
virtual void Log(
    LoggerCategory category,
    Func<String^>^ messageGenerator
) sealed
abstract Log :
        category : LoggerCategory *
        messageGenerator : Func<string> -> unit
override Log :
        category : LoggerCategory *
        messageGenerator : Func<string> -> unit

Parameters

category
Type: HandlebarsDotNet.MvcLoggerCategory
The category the message is used for.
messageGenerator
Type: SystemFunc String

Implements

ILoggerLog(LoggerCategory, FuncString)
See Also

Reference

NullLogger Class


NullLogger.Trace Method

NullLoggerTrace Method
The NullLogger does nothing in this ILogger implementation.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public void Trace(
    LoggerCategory category,
    Func<string> messageGenerator
)
Public Sub Trace (
    category As LoggerCategory,
    messageGenerator As Func(Of String)
)
public:
virtual void Trace(
    LoggerCategory category,
    Func<String^>^ messageGenerator
) sealed
abstract Trace :
        category : LoggerCategory *
        messageGenerator : Func<string> -> unit
override Trace :
        category : LoggerCategory *
        messageGenerator : Func<string> -> unit

Parameters

category
Type: HandlebarsDotNet.MvcLoggerCategory
The category the message is used for.
messageGenerator
Type: SystemFunc String

Implements

ILoggerTrace(LoggerCategory, FuncString)
See Also

Reference

NullLogger Class


NullLogger.Warn Method

NullLoggerWarn Method
The NullLogger does nothing in this ILogger implementation.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public void Warn(
    LoggerCategory category,
    Func<string> messageGenerator
)
Public Sub Warn (
    category As LoggerCategory,
    messageGenerator As Func(Of String)
)
public:
virtual void Warn(
    LoggerCategory category,
    Func<String^>^ messageGenerator
) sealed
abstract Warn :
        category : LoggerCategory *
        messageGenerator : Func<string> -> unit
override Warn :
        category : LoggerCategory *
        messageGenerator : Func<string> -> unit

Parameters

category
Type: HandlebarsDotNet.MvcLoggerCategory
The category the message is used for.
messageGenerator
Type: SystemFunc String

Implements

ILoggerWarn(LoggerCategory, FuncString)
See Also

Reference

NullLogger Class


NullLogger Properties

NullLogger Properties

The NullLogger type exposes the following members.

Properties
Name | Description
Instance | A singleton instance of NullLogger.
Top
See Also

Reference

NullLogger Class


NullLogger.Instance Property

NullLoggerInstance Property
A singleton instance of NullLogger.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
C#
VB
C++
F#
Copy
public static ILogger Instance { get; }
Public Shared ReadOnly Property Instance As ILogger
    Get
public:
static property ILogger^ Instance {
    ILogger^ get ();
}
static member Instance : ILogger with get

Property Value

Type: ILogger
See Also

Reference

NullLogger Class