Accessing IUmbracoContextFactory in static extension class
Hi,
How can I access an IUmbracoContextFactory such as umbracohelper in an static class.
So basically, I want to render a grid and I have an HtmlHelperExtention class with an GetGridHtml method and I want to query the content by its unique identifier.
public static MvcHtmlString GetGridHtml(this HtmlHelper html, IUmbracoContextFactory Umbraco, int id, string propertyAlias = "contentGrid", string framework = "ContentGrid")
{
using (var cref = Umbraco.EnsureUmbracoContext())
{
var cache = cref.UmbracoContext.Content;
var property = cache.GetById(id);
return html.GetGridHtml(property, propertyAlias, framework);
}
}
But i am getting an error when I want to use this extention method from my razor view
@Html.GetGridHtml(this.UmbracoContext, Model.Id)
Whats the best practice of passing in the umbraco context object to extention static class?
I solved this by passing the Umbraco helper object from my view as I read in the documentation
All Razor views that Umbraco creates expose an UmbracoContext property which is the UmbracoContext, they expose an ApplicationContext property which is Umbraco's ApplicationContext.
@Html.GetGridHtml(Umbraco, Model.Id)
I hope this is a correct and best practice way of doing this
Accessing IUmbracoContextFactory in static extension class
Hi, How can I access an IUmbracoContextFactory such as umbracohelper in an static class.
So basically, I want to render a grid and I have an HtmlHelperExtention class with an GetGridHtml method and I want to query the content by its unique identifier.
But i am getting an error when I want to use this extention method from my razor view
Whats the best practice of passing in the umbraco context object to extention static class?
I solved this by passing the Umbraco helper object from my view as I read in the documentation
I hope this is a correct and best practice way of doing this
is working on a reply...