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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With