代码之家  ›  专栏  ›  技术社区  ›  Xpleria Dholu

在Nancy中使用SSVE时访问视图中的词典项

  •  0
  • Xpleria Dholu  · 技术社区  · 8 年前

    我在向我的观点传递一本词典。但我无法访问字典中的对象。

    在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
    

    但我没有得到数据。

    1 回复  |  直到 8 年前
        1
  •  0
  •   Xpleria Dholu    8 年前

    来自@erdomke's Comment ,我们可以使用 @Current.Value .

    具体如下:

    @Each
        @Current.Key: @Current.Value.Firstname
    @EndEach
    

    这将给出输出:

    型号:Nancy信息:信息