Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# fubumvc-将集合呈现为下拉列表_C#_Fubumvc - Fatal编程技术网

C# fubumvc-将集合呈现为下拉列表

C# fubumvc-将集合呈现为下拉列表,c#,fubumvc,C#,Fubumvc,我无法理解如何将集合呈现为下拉列表 如果我有这样一个模型: public class AccountViewModel { public string[] Country { get; set; } } 我希望字符串集合呈现为下拉列表 使用html页面助手InputFor似乎不起作用。它只是一个文本框 我注意到InputFor可以反映属性类型并相应地呈现html。(类似于布尔字段的复选框) 我还注意到FubuPageExtensions有CheckBoxFo

我无法理解如何将集合呈现为下拉列表

如果我有这样一个模型:

public class AccountViewModel {             

    public string[] Country { get; set; }
}
我希望字符串集合呈现为下拉列表

使用html页面助手InputFor似乎不起作用。它只是一个文本框

我注意到InputFor可以反映属性类型并相应地呈现html。(类似于布尔字段的复选框)

我还注意到FubuPageExtensions有CheckBoxFor和TextBoxFor方法,但没有与DropDownListFor等效的方法

在理解fubu中的html约定时,我可能遗漏了一些非常基本的东西

我需要自己构建select标记吗?如果是这样的话,推荐的方法是什么?

您是正确的(在我上次查看时),没有FubuMVC.Core HTML扩展方法用于生成选择标记,尽管您可以使用通过代码生成选择标记

当您在问题中触及时,正确的攻击方法可能是使用HTML约定和HtmlTags库,如示例“src/UI/htmlconversationswithPageExtensions”中所示

例如,枚举生成示例可能是:

this.Editors
    .If(e => e.Accessor.PropertyType.IsEnum)
    .BuildBy(er =>
    {
        var tag = new HtmlTag("select");
        var enumValues = Enum.GetValues(er.Accessor.PropertyType);
        foreach (var enumValue in enumValues)
        {
            tag.Children.Add(new HtmlTag("option").Text(enumValue.ToString()));
        }

        return tag;
    });
Recipes存储库是一个非常新的并且还在增长的库,所以可能会有一些更好的例子,但是希望这能给你一些想法