使用 razor 引擎的 @helper 事物和委托来发出 html
我可能在这里遗漏了一些非常基本的语法陷阱。然而,Razor 可能还不够聪明,无法'理解'
html 在像这样的委托内完成的输出(因为缺乏与制作相关的任何人的官方文档)后者,我必须在这里发布):
@{
ParallelQuery pQuery = rootData.ChildNodes.AsParallel();
Func<ParallelQuery, string> builderAction = delegate
{
while (rootData.HasChildNodes)
{
foreach (SiteMapNode node in pQuery)
{
<li><a href="@node.Url">@node.Title</a></li> //CANT SEE ANY HTML TAGS AVAIL TO SPEW
}
}
return string.Empty;
};
};
但在代表身体之外:
//CHARM - BUT I WANT TO USE DELEGATES, WHY NOT??
@{
foreach(var x in new string[100]) {
<li>
<a href="@x">@x</a>
</li>
};
这张照片有什么问题?
编辑1:
我在这里做了一些奇怪的事情吗,只是为了构建一个带有链接的树列表?这似乎比 Razor 轻松泪水所想象的要复杂一些。
I am probably missing some very basic syntax gotcha in here. Yet it might that the Razor not smart enough yet to 'understand'
html output done inside a delegate like this (for the lack of official documentation from anybody related to the makings of the latter, I have to post this here):
@{
ParallelQuery pQuery = rootData.ChildNodes.AsParallel();
Func<ParallelQuery, string> builderAction = delegate
{
while (rootData.HasChildNodes)
{
foreach (SiteMapNode node in pQuery)
{
<li><a href="@node.Url">@node.Title</a></li> //CANT SEE ANY HTML TAGS AVAIL TO SPEW
}
}
return string.Empty;
};
};
YET JUST OUTSIDE OF THE DELEGATE BODY:
//CHARM - BUT I WANT TO USE DELEGATES, WHY NOT??
@{
foreach(var x in new string[100]) {
<li>
<a href="@x">@x</a>
</li>
};
What's wrong with this picture??
Edit 1:
Am I doing something weird here, just to build a tree list with links? It seems a bit more complicated than what the Razor's supposed to be all about in tearms of ease.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您运行任何并行查询时,页面的执行将继续运行。
当并行查询完成运行时,.net 已经将您的页面发送到客户端。
如果您在 Ajax 调用的函数内运行并行查询,它也不起作用。
不知何故,您需要等到并行查询完成,因为它是非阻塞的。因此,在运行并行查询的代码结束时,您需要以某种方式等待直到其完成。
Execution of the page continues to run as you're running any parallel queries.
By the time your parallel query finished running .net already sent your page to the client.
If you run a parallel query inside the function Ajax is calling it wouldn't work either.
Somehow you'll need to wait until a parallel query has finished because it's non-blocking. So at the end of your code running the parallel query you'll need to wait somehow until its finished.