我有一个Kendo.DropDownList,它将显示区域性。
第一次加载DropDown时,我想将其默认的选定值设置为当前区域性。
这是下拉列表:
@(Html.Kendo().DropDownList()
.Name("culture")
.DataValueField("Value")
.DataTextField("DisplayText")
.DataSource(dataSource =>
{
dataSource.Read(read =>
{
read.Action("PopulateCultures", "CultureSelector");
});
})
.Events(events =>
{
events.Select("onCultureChange");
})
.SelectedIndex(0)
)
这是我要填充的地方:
public ActionResult PopulateCultures()
{
CultureModel cm = new CultureModel();
string uCulture = System.Threading.Thread.CurrentThread.CurrentUICulture.ToString();
List<Culture> cultures = null;
cultures = cm.PopulateCulture();
if (Session["SiteUICulture"] != null) uCulture = Session["SiteUICulture"].ToString();
try
{
//Here I need to set default/selected value to a culture
cultures = cm.PopulateCulture();
}
catch (Exception e)
{
}
return Json(cultures, JsonRequestBehavior.AllowGet);
}
模型:
公共类CultureModel { 公共字符串CurrentName {get;组; }
public List<Culture> AvailableCultures { get; set; }
public List<Culture> PopulateCulture()
{
ClientServer iClient = new ClientServer();
AvailableCultures = iClient.GetCultures(applicationName).ToList();
return AvailableCultures;
}
}
我该怎么做?
答案 0 :(得分:0)
尝试以下步骤:-
例如: 与您的下拉列表绑定的可用文化是:- [{Id = 1,Name = English-US},{Id = 2,Name = English-UK}]
如果您添加的属性的名称为SelectedCulture 您的控制器会将其设置为可用值,例如SelectedCulture = 1
您的视图将在下拉菜单中设置值
@(Html.Kendo().DropDownList()
.Name("culture")
.DataValueField("Value")
.DataTextField("DisplayText")
.DataSource(dataSource =>
{
dataSource.Read(read =>
{
read.Action("PopulateCultures", "CultureSelector");
});
})
.Events(events =>
{
events.Select("onCultureChange");
})
.Value(Model.SelectedCulture)
);