0

I need to get the current culture in a controller in a custom module; I know how to get it from a razor view:

@{
    var currentCulture = WorkContext.CurrentCulture;
}

but in the controller I have no access to the WorkContext and I can't find anything similar (I tried HttpContext but there is no CurrentCulture method).

Daniele Armanasco
  • 7,289
  • 9
  • 43
  • 55

1 Answers1

1

You can inject the WorkContextAccessor into your controller and get the current WorkContext

private readonly IWorkContextAccessor _wca;

public MyController(IWorkContextAccessor wca) {
    _wca = wca;
}

public ActionResult Index() {
    var workContext = _wca.GetContext();
}

The WorkContext is also available on the IOrchardServices interface

Hazza
  • 6,441
  • 3
  • 24
  • 37