C# 在MVC4中从字符串类型下拉列表
型号代码C# 在MVC4中从字符串类型下拉列表,c#,asp.net-mvc-4,C#,Asp.net Mvc 4,型号代码 public class ConfigureModel { public bool Responsive { get; set; } public string Theams { get; set; } } 控制器 ConfigureModel model = new ConfigureModel(); model.Responsive = bootStrapCoreSettings.Re
public class ConfigureModel
{
public bool Responsive { get; set; }
public string Theams { get; set; }
}
控制器
ConfigureModel model = new ConfigureModel();
model.Responsive = bootStrapCoreSettings.Responsive ;
//model.Theams = bootStrapCoreSettings.Theams;
var theams = "lsdjfldsk;lkdfjlsd;jldskfj;dlksfj;";
model.Theams = them.Split(new char[] { ';' });
如何将AMS值放入下拉列表 在代码中需要一个指南或代码 型号。THAMS应为数组类型 将其转换为列表或数组后,只需将其传递给
@HTML.EditorFor(model=>Theams)
它将是下拉列表。在您的代码中
型号。THAMS应为数组类型
将其转换为列表或数组后,只需将其传递给@HTML.EditorFor(model=>Theams)
它将是下拉列表。型号代码
public class ConfigureModel
{
public bool Responsive { get; set; }
public SelectList TheamsList { get; set; }
public string SelectedTheam { get; set; }
}
动作码
ConfigureModel model = new ConfigureModel();
var theams = "lsdjfldsk;lkdfjlsd;jldskfj;dlksfj;";
// If you don't want a blank value for the bit after the last ';'
theams = theams.TrimEnd(';');
var theamsSplit = theams.Split(new char[] { ';' }).ToDictionary(s => s, s => s);
model.TheamsList = new SelectList(theams, "Key", "Value");
视图代码
@Html.DropDownListFor(m => m.SelectedTheam, Model.TheamsList)
Tangent:你是指主题而不是主题吗?模型代码
public class ConfigureModel
{
public bool Responsive { get; set; }
public SelectList TheamsList { get; set; }
public string SelectedTheam { get; set; }
}
动作码
ConfigureModel model = new ConfigureModel();
var theams = "lsdjfldsk;lkdfjlsd;jldskfj;dlksfj;";
// If you don't want a blank value for the bit after the last ';'
theams = theams.TrimEnd(';');
var theamsSplit = theams.Split(new char[] { ';' }).ToDictionary(s => s, s => s);
model.TheamsList = new SelectList(theams, "Key", "Value");
视图代码
@Html.DropDownListFor(m => m.SelectedTheam, Model.TheamsList)
Tangent:您是指主题而不是主题吗?您的代码甚至无法编译:
// You try to assign an array to a string
model.Theams = them.Split(new char[] { ';' });
尝试将配置模型类更改为:
public class ConfigureModel
{
public bool Responsive { get; set; }
public List<string> Theams { get; set; }
}
然后你有一个填充模型。在razor视图中使用此选项:
@Html.DropDownListFor( m => m.Theams, new SelectList(Model.Theams))
您的代码甚至不编译:
// You try to assign an array to a string
model.Theams = them.Split(new char[] { ';' });
尝试将配置模型类更改为:
public class ConfigureModel
{
public bool Responsive { get; set; }
public List<string> Theams { get; set; }
}
然后你有一个填充模型。在razor视图中使用此选项:
@Html.DropDownListFor( m => m.Theams, new SelectList(Model.Theams))
要在视图中使用Html.Dropdownlist,您需要在模型中有一个
IEnumerable selectList
。因此,您的模型将更改如下:
public class ConfigureModel
{
public bool Responsive { get; set; }
public IEnumerable<string> TheamsList { get; set; }
}
要在视图中使用Html.Dropdownlist,您需要在模型中有一个
IEnumerable selectList
。因此,您的模型将更改如下:
public class ConfigureModel
{
public bool Responsive { get; set; }
public IEnumerable<string> TheamsList { get; set; }
}
model.Theams=theme.Split(新字符[]{';'});//是真正编译的??model.Theams=theme.Split(新字符[]{';'});//真的被编译了吗?名字中没有MVC4。名字中没有MVC4。