我可能做错了此事(我无法找到任何其他方式进行操作的文档)。在区域中创建ViewComponent时,搜索路径不正确:
namespace HelloWorld
{
[Area("Test")]
public class HelloViewComponent : ViewComponent
{
public IViewComponentResult Invoke()
{
return View();
}
}
}
Run Code Online (Sandbox Code Playgroud)
而不是在/Areas/Test/Views/Components/Hello/Default.cshtml以下位置搜索视图,将引发以下异常:
InvalidOperationException: The view 'Components/Hello/Default' was not found. The following locations were searched:
/Views/Home/Components/Hello/Default.cshtml
/Views/Shared/Components/Hello/Default.cshtml.
Run Code Online (Sandbox Code Playgroud)
我通过执行以下操作来调用视图:(在中/Views/Home/Index.cshtml)
@Component.Invoke("Hello")
Run Code Online (Sandbox Code Playgroud)
似乎没有办法包括从中调用视图的区域。
关于从Area内调用ViewComponent的正确方法的任何想法,或者以上方法不正确并且我犯了一个错误。
我正在尝试为节点中的MongoDB中存储的页面生成URL.
使用以下函数,我想遍历一个javascript对象,并显示每个元素的路径.
我几乎在那里,但我被卡住了 - 使用Async甚至可能有更好的方法来做到这一点(我必须承认,让我有点困惑).
功能:( 演示)
function printTree(people, slug) {
for (var p = 0; p < people.length; p++) {
var root = people[p];
slug = slug + root.name + "/";
console.log(slug);
if (root.children.length > 0) {
var childrenCount = root.children.length;
for (var c = 0; c < childrenCount; c++) {
if (root.children[c].children.length > 0) {
printTree(root.children[c].children, slug + root.children[c].name + "/");
}
}
}
}
};
Run Code Online (Sandbox Code Playgroud)
输出:
/michael/
/michael/angela/oscar
/michael/meredith/creed
/michael/meredith/creed/kelly
Run Code Online (Sandbox Code Playgroud)
预期产出:
/michael/
/michael/angela/
/michael/angela/oscar/
/michael/meredith/
/michael/meredith/creed/ …Run Code Online (Sandbox Code Playgroud)