当我包括默认值时,为什么Bootstrap Select不显示选定的值?

问题描述 投票:0回答:1

[当我有一个设置了值的对象时,仅当我忽略"--Select--"参数时才显示该对象。

知道为什么会这样吗?

@Html.DropDownListFor(m => m.FlightDetails.AirlineId, ViewBag.AirlineList as SelectList, "--Select--", new { @class = "form-control selectpicker", @data_live_search = "true", @id = flight.Id + "AirlineId" })
asp.net-mvc bootstrap-4 bootstrap-select
1个回答
0
投票

服务器端

您应该为第三个参数设置默认值,如下所示(注意SelectedDefaultValueHere

var ViewBag.AirlineList = new SelectList(`listOfItemHere`,
    "ValueOfDropdownItem", 
    "TextToDisplay",  
    SelectedDefaultValueHere);

或者您可以这样设置SelectedSelectListItem

new SelectListItem()
{
   Value = "anyValue",
   Text = "AnyText",
   Selected = true
};
© www.soinside.com 2019 - 2024. All rights reserved.