Reputation: 25312
I have Razor function which outputs some data and as result does not return anything (that's a long story why it is done this way):
@functions
{
public static void SampleHelperMethod()
{
//...
}
}
How can I call it in view now? I tried @MyFunctions.SampleHelperMethod()
but it doesn't work for void functions.
Upvotes: 6
Views: 3662
Reputation: 39817
Declaration
@functions
{
public static void TestFunction()
{
}
}
Use in View
@{ TestFunction(); }
Because this is a function that does not return anything, you need to wrap it in the braces like you would and if/for statement. However, like Erik said, it is really unclear why this logic would be declared in the view...you may consider creating a helpers class that your views can include. This will allow for reuse and better separations of concerns.
Upvotes: 11