1

Is there a way to share functions with html code between .cshtml views in ASP.NET Core? I need it to work similar to helpers, so it can be accessible from a few views. I know that some functions can be shared if moved to a .cs file, but I've never seen cs functions with complex html code. Function example (in project they are much more complex and multiline):

@{
    async Task Test(string test)
    {
        <div class="test">String @test</div>
    }
}

Now I'm using a partial views with functions declared inside, but I do not like how it works.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Kania223
  • 11
  • 1
  • Does this answer you ? [Single .NET Core Razor C# functions in all Views](https://stackoverflow.com/questions/46603562/single-net-core-razor-c-sharp-functions-in-all-views) – Qing Guo Jan 02 '23 at 09:57
  • Unfortunately not, because my functions are in .cshtml files not .cs files and because of complex html code to my mind it will be hard to move them to .cs files. – Kania223 Jan 03 '23 at 11:50

0 Answers0