Georgi Kovachev Georgi Kovachev - 1 year ago 111
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download