I have a configuration that I need to pass to the master layout file. This configuration has data that gets displayed in the header, footer, and other various places in the application. I need this configuration to get injected into the master layout file for every request to the application.
However, I need to load this configuration from a Web API, and I'd like the code to be asynchronous. I haven't had much luck finding a solution.
Rendering a partial view, this does not work because in MVC 5 you cannot render partial views asynchronously
@Html.RenderAction, this will also not work for the same reason as above.
Overriding the default base controller with DefaultRenderMvcControllerResolver.Current.SetDefaultControllerType(typeof(MyCustomBaseController)); but this does not have an asynchronous OnActionExecuting method
Any help is much appreciated, I'm pretty stuck here.
Not really answering the questions. But I am wondering why you are stuck on "async". Async is good for going to slow devices like hdd/network. So do you really need this. If so, loading data from a partial is not what I consider a good practice. You should load data in a controller, manipulate it, and pass it to the (view)model.
To come back to your question: why don't you load data from the controller. Will be easier to load async from there.
A second remark. Why do you mean with "to get injected". Because you can override the UmbracoViewPage<> and add a constructor to allow dependency injection in your ViewPage. This then allows you to get the necessary values from your view.
The configuration comes from a WebApi, which is a network call, so that is why I'd like to to be async. The config contains properties that need to be used in the layout file that can change (phone number, contact info, etc).
I'd like to load this data in the controller, I understand that's the best way, but I haven't found a way to load this data for every route in the controller. I've tried setting up a custom base controller, but the OnActionExecuting method is not async.
Otherwise, I would have to hijack every route in Umbraco manually to load this config, and we need to be able to stand up pages dynamically.
By injected, I mean that the config just needs to be added to the view. I already have IoC setup and working.
Load View Configuration Asynchronously
I have a configuration that I need to pass to the master layout file. This configuration has data that gets displayed in the header, footer, and other various places in the application. I need this configuration to get injected into the master layout file for every request to the application.
However, I need to load this configuration from a Web API, and I'd like the code to be asynchronous. I haven't had much luck finding a solution.
So far I've tried:
DefaultRenderMvcControllerResolver.Current.SetDefaultControllerType(typeof(MyCustomBaseController));
but this does not have an asynchronous OnActionExecuting methodAny help is much appreciated, I'm pretty stuck here.
Not really answering the questions. But I am wondering why you are stuck on "async". Async is good for going to slow devices like hdd/network. So do you really need this. If so, loading data from a partial is not what I consider a good practice. You should load data in a controller, manipulate it, and pass it to the (view)model.
To come back to your question: why don't you load data from the controller. Will be easier to load async from there.
A second remark. Why do you mean with "to get injected". Because you can override the UmbracoViewPage<> and add a constructor to allow dependency injection in your ViewPage. This then allows you to get the necessary values from your view.
Hope it helps a bit.
Kind regards
Damiaan
The configuration comes from a WebApi, which is a network call, so that is why I'd like to to be async. The config contains properties that need to be used in the layout file that can change (phone number, contact info, etc).
I'd like to load this data in the controller, I understand that's the best way, but I haven't found a way to load this data for every route in the controller. I've tried setting up a custom base controller, but the OnActionExecuting method is not async.
Otherwise, I would have to hijack every route in Umbraco manually to load this config, and we need to be able to stand up pages dynamically.
By injected, I mean that the config just needs to be added to the view. I already have IoC setup and working.
If IoC works, extending the ViewPage is an easy way to inject something in your view.
You can replace the default controller easily.
What you could do is create a Html.Action (which is also a controller) and can be loaded from the master template with @Html.Action("...")
You can't load @Html.Action from the view asynchronously. This is the exception you get when I've tried that.
HttpServerUtility.Execute blocked while waiting for an asynchronous operation to complete
.I have replaced the default controller, yes that is easy. But I can't find a way to use that new default controller to run an action on every request.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.