Why can't one Razor helper call another helper?

I run the razor code below in the .cshtml file (this is a simplified version of something more complex that I need to achieve), but the renderTestB does not seem to execute.

 @renderTestA("test string 1", "test string 2"); @helper renderTestA(string input1, string input2) { <div> @renderTestB(input1) @renderTestB(input2) </div> } @helper renderTestB(string input) { <p class="test">@input</p> } 

Why is this? And is there any other way to achieve what I'm trying to do?

I understand that I could duplicate paragraph code inside the renderTestA , but obviously would prefer to use a reusable code solution.

+6
source share
1 answer

How about this?

 @renderTestA(renderTestB("test string 1"), renderTestB("test string 2")) @helper renderTestA(string input1, string input2) { <div> @input1 @input2 </div> } @helper renderTestB(string input) { <p class="test">@input</p> } 

Instead, you should use editor / display templates or custom HTML helpers, as @helper functionality was used before these functions became normal.

Regarding why you cannot invest them. It introduces a number of problems that are easy to avoid using the syntax above. For example ... if you have a looping cycle of nested helpers, this can easily cause a stack overflow.

0
source

All Articles