在ASP.NET Core中替换@helper [英] Replacement for @helper in ASP.NET Core

查看:344
本文介绍了在ASP.NET Core中替换@helper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我认为ViewComponent不能解决TagHelper的问题.有什么替代品吗?带有参数并返回HtmlString?

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

就目前而言,我认为它是在RC之前的一个临时删除. https://github.com/aspnet/Razor/issues/281 https://github.com/aspnet/Mvc/issues/1130 好!最好是.我希望有人在努力.如果没有@helper,则构建大型HtmlString或模板"将是一个严重的难题.

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.

第二,App_Code文件夹发生了什么事?

Secondly, what happened to the App_Code folder?

推荐答案

@{
    Func<String, IHtmlContent> foo = @<div>Say @item</div>;
}

这篇关于在ASP.NET Core中替换@helper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆