Razor injection code from string

I have a razor fragment stored in a line:

@if (Request.IsAuthenticated) { <h1>Hello World</h1> } 

I keep a piece of code in my cache. How can I insert a string so that it appears as if it were part of the original view file, also executing code?

I tried:

 @ApplicationCache.GetDynamicString("MyString") @Html.Raw(ApplicationCache.GetDynamicString("MyString")) 

These methods return a string, not an MvcHtmlString. I could dynamically write to a partial view from my server and display a partial view, but I wonder if there is an assistant that I don't see.

+6
source share

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


All Articles