【发布时间】:2018-02-08 17:42:13
【问题描述】:
我正在将字典传递给我的视图。但我无法访问字典中的对象。
在 Nancy 中使用 SSVE 时,我们如何在视图中读取字典?这是我的代码:
帮助模块
public class HelpModule : NancyModule
{
public HelpModule()
{
Get["/help/"] = _ => View["index"];
Get["/help/faqs/"] = parameters => {
return Negotiate
.WithModel(new Dictionary<string, object>
{
{ "model" , new RatPack { FirstName = "Nancy " } },
{ "info" , new RatPack { FirstName = "Info " } }
})
.WithView("faqs")
.WithHeader("X-Custom", "SomeValue");
};
}
}
public class RatPack
{
public string FirstName;
}
查看
@Each
@Current
@EndEach
我得到的输出是
[模型,WebService.Website.Website.Modules.Help.RatPack] [信息,WebService.Website.Website.Modules.Help.RatPack]
我尝试了以下方法:
@Each
@Current["info"]
@EndEach
@Each
@Current.info
@EndEach
但我没有得到数据。
【问题讨论】:
-
只是在黑暗中刺伤,但我假设在循环的上下文中,
@Current是KeyValuePair<string,RatPack>。因此,@Current.Value会起作用吗? -
感谢您的建议,可行!
标签: c# .net dictionary nancy