到目前为止,我认为 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 之前的临时删除.github/aspnet/Razor/issues/281 和 github/aspnet/Mvc/issues/1130 好吧!最好是.我希望有人正在为此努力.如果没有 @helper,构建大型 HtmlString 或模板"将是一个严重的痛苦.
For now i believe its a temporary delete before RC. github/aspnet/Razor/issues/281 and github/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?
推荐答案根据以下 Github issue,看来@helper 又回来了,将包含在 asp core 3.0.0 preview 4 中.
According to the following Github issue, it looks like @helper is coming back and will be included in asp core 3.0.0 preview 4.
github/aspnet/AspNetCore/issues/5110
更新
从 asp core 3 开始,您现在可以在 Razor 代码块中定义本地函数.
Starting in asp core 3, you can now define a local function within a Razor code block.
@{ void RenderName(string name) { <p>Name: <strong>@name</strong></p> } RenderName("Mahatma Gandhi"); RenderName("Martin Luther King, Jr."); }docs.microsoft/en-us/aspnet/core/mvc/views/razor?view=aspnetcore-3.1#razor-code-blocks
或者,您可以像这样使用@functions 指令:
Alternatively you can use the @functions directive like this:
@{ RenderName("Mahatma Gandhi"); RenderName("Martin Luther King, Jr."); } @functions { private void RenderName(string name) { <p>Name: <strong>@name</strong></p> } }docs.microsoft/en-us/aspnet/core/mvc/views/razor?view=aspnetcore-3.1#functions
更多推荐
替换 ASP.NET Core 中的 @helper
发布评论