Click or drag to resize
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
public static ViewContext GetViewContext(
	Object context
)

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
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
public ActionResult Index()
{
    var model = new { pi = 3.14159265358979 };
    return View(model);
}
index.hbs
{{formatvalue pi "Pi is about {0:N}"}}
Renders
Pi is about 3.14
See Also