Asynchronous method call in Razor mode

I have a @ Html.Translate () extension method that returns the translated string. Translations are stored in the database, so I want to make an asynchronous call to the database from a helper method. Can I make asynchronous method calls from a razor? Is there a way around a razor-mode asynchronous call method?

+4
source share
1 answer

Asynchronous method calls from the razor view are supported (or will be supported) only in ASP.NET vNext (MVC 6).

If you are using MVC 5 and eralier, the easiest solution to your problem would be to add a property to your view model and populate it with an asynchronous call to db. Therefore, when your view is displayed, all the data will already be in the model and ready for use.

PS , also calling the database from view, sounds a bit suspicious. Perhaps you should consider this template.

+6
source

Source: https://habr.com/ru/post/1606236/


All Articles