Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Actually HelperResult is something Microsoft would rather you didn't use, as evidenced by documentation:</p> <blockquote> <p>public class HelperResult : IHtmlString in namespace System.Web.WebPages</p> <p>Summary: This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.</p> </blockquote> <p>A possible solution to your problem might be to wrap your description function in another helper and then pass that helper as a <a href="https://stackoverflow.com/questions/886822/what-is-a-method-group-in-c">method group</a> to your node helper, like this:</p> <pre><code>@helper Node(string title, Func&lt;HelperResult&gt; descriptions) { &lt;div&gt;@descriptions()&lt;/div&gt; } @helper Description() { &lt;span&gt;desc1&lt;/span&gt; &lt;span&gt;desc2&lt;/span&gt; } @Node("title", Description) </code></pre> <p>In any case, your first idea shouldn't work because a parameter of type Func is in fact equal to a parameterless function, in which case you need to write the lambda expression like this:</p> <pre><code>myFunction( () =&gt; doSomething) </code></pre> <p>So your function call would have been:</p> <pre><code>@node("title", () =&gt; @&lt;text&gt; &lt;span&gt;"desc1"&lt;/span&gt; &lt;span&gt;"desc2"&lt;/span&gt; &lt;/text&gt;) </code></pre> <p>Since the future of these helpers is <a href="https://stackoverflow.com/questions/4451287/razor-declarative-html-helpers">a bit dubious</a> though, I would consider switching to either <a href="http://develoq.net/2011/how-to-create-custom-html-helpers-for-asp-net-mvc-3-and-razor-view-engine/" rel="nofollow noreferrer">HtmlHelpers</a> for small snippets of html or <a href="http://rachelappel.com/razor/partial-views-in-asp-net-mvc-3-w-the-razor-view-engine/" rel="nofollow noreferrer">Partials</a> for larger chunks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload