Georgi Kovachev Georgi Kovachev - 8 days ago 6
ASP.NET (C#) Question

Razor C# Create function / use it in another file

I created a function in one file func.cshtml like this.

@functions {
int sum(a, b)
{
return a+b;
}
}


and I want to use this function in another file.

There are several links I can find, but they are for an older version and won't work for what I want to do.

Answer

You should move that function from the view file into a .cs file, then call it from views that need it.