Reputation: 17004
I need to pass HTML as Parameter to a Html Helper Method (e.g: ClientTemplate in Telerik's Kendo UI MVC Wrapper).
Basicly I try to pass this:
<ul class="list-unstyled">
<li>Foo</li>
<li>Bar</li>
<li>Baz</li>
</ul>
I tried this:
.Template(@<text>
<ul class="list-unstyled">
<li>Foo</li>
<li>Bar</li>
<li>Baz</li>
</ul>
</text>.ToString()))
I get this error
CS1660 Cannot convert lambda expression to type 'string' because it is not a delegate type
I know it is possible with "...<li>Foo</li><li>Bar</li>..."
but I am wondering if there is a better method like razors <text>
Upvotes: 1
Views: 511
Reputation: 17004
Thanks to Ashish Emmanuel's comment, I have this solution:
Helper Method
public static string RazorTemplateHelper(Func<object, HelperResult> template)
{
return template.Invoke(null).ToString();
}
Razor
.Template(RazorTemplateHelper(@<text>
<ul class="list-unstyled">
<li>Foo</li>
<li>Bar</li>
<li>Baz</li>
</ul>
</text>))
Upvotes: 2