【发布时间】:2021-04-17 17:27:09
【问题描述】:
我的应用程序是 MVC5。我正在填充国家剑道下拉列表,试图将加拿大和美国置于列表顶部:
public JsonResult GetCountries()
{
return Json(db.Country.OrderBy(x => x.TwoCharCountryCode == "CA")
.ThenBy(x => x.TwoCharCountryCode == "US").ThenBy(x => x.CountryName)
.Select(c => new { CountryId = c.CountryId, CountryName = c.CountryName }), JsonRequestBehavior.AllowGet);
}
@(Html.Kendo().DropDownList()
.Name("Country")
.HtmlAttributes(new { style = "width:300px;", id="Country", value = ViewBag.CountryId })
.OptionLabel("Select country...")
.DataTextField("CountryName")
.DataValueField("CountryId")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetCountries", "Home");
}).ServerFiltering(true);
})
.Events(e => {e.Select("onSelect");
}))
我可以使用两个 ThenBy 吗?还是我做错了什么?
【问题讨论】:
标签: asp.net-mvc entity-framework linq kendo-ui