Replacement for @helper in ASP.NET Core

Ifeanyi Chukwu picture Ifeanyi Chukwu · Sep 1, 2015 · Viewed 14.2k times · Source

So far, i don't think ViewComponent solves that neither does TagHelper. Is there any replacement to this? Something that takes parameters and returns a HtmlString?

I don't see anything harmful with:

@helper foo(string something) {
     <div>Say @something</div>
}

var emailbody = classfilenameinAppCodefolder.foo("hello"); //store result in a variable for further processes

For now i believe its a temporary delete before RC. https://github.com/aspnet/Razor/issues/281 and https://github.com/aspnet/Mvc/issues/1130 Well! it better be. I hope someone is working on it. Without @helper, building large HtmlString or 'template' would be a serious pain.

Note: Partial View doesn't seem to do the trick. I think it only renders views not return view to variable.

Secondly, what happened to the App_Code folder?

Answer

Alexaku picture Alexaku · Mar 24, 2016
@{
    Func<String, IHtmlContent> foo = @<div>Say @item</div>;
}