-1

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.

Michael Armes
  • 1,056
  • 2
  • 17
  • 31
Georgi Kovachev
  • 633
  • 1
  • 10
  • 25
  • That answer is not working. I also left a comment there. I have this error. CS0120: An object reference is required for the non-static field, method, or property 'Functions.AgoDateString()' – Georgi Kovachev Dec 01 '16 at 22:52
  • Did you declare it in a file named `Functions.cshtml`, or in `func.cshtml` as in this question? – Rob Dec 01 '16 at 23:24

1 Answers1

2

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

Hari Lubovac
  • 622
  • 4
  • 14