怎么调整@Html.Dropdownlist的宽度呢?数据不显示
How to adjust the width of @Html.Dropdownlist for? The data are not showing
我使用@Html.DropDownLinkFor 在我的系统上选择支付选项。但是发生的事情是,它没有在下拉框中显示默认文本。当你勾选一个选项时,它仍然不会显示?如何使文本显示在下拉框上或调整其宽度?
这是我的代码
<td>
@Html.DropDownListFor(model => item.LevelId, new SelectList(item.GradeLevels, "LevelId", "LevelName", item.LevelId),
"<- Select Level ->",
new { @class = "form-control ddlClass", @id = "LevelId_" + item.TransactionId + "_" + item.StudentId})
</td>
DropDownList 助手的第二个参数必须是一个 IEnumerable。
请逐步尝试。
步骤 1)
@Html.DropDownList(
"ListId",
Enumerable.Empty<SelectListItem>(),"<- Select Level ->",
new { style = "width: 360px;" }
)
第 2 步)
您想用来绑定到:
@Html.DropDownList(
"ListId",
Model.PaymentMethodList,"<- Select Level ->",
new { style = "width: 360px;" }
)
步骤 3)
避免让您的 HTML 与您应该使用外部样式的样式混淆 CSS:
@Html.DropDownListFor(
x => x.ListId,
Model.PaymentMethodList,"<- Select Level ->",
new { @class = "mydropdown" }
)
您的外部 Css 代码
.mydropdown{
width: 360px;
}
如果问题仍然存在,请检查您的 css 和脚本或分享更多您的代码。
我使用@Html.DropDownLinkFor 在我的系统上选择支付选项。但是发生的事情是,它没有在下拉框中显示默认文本。当你勾选一个选项时,它仍然不会显示?如何使文本显示在下拉框上或调整其宽度?
这是我的代码
<td>
@Html.DropDownListFor(model => item.LevelId, new SelectList(item.GradeLevels, "LevelId", "LevelName", item.LevelId),
"<- Select Level ->",
new { @class = "form-control ddlClass", @id = "LevelId_" + item.TransactionId + "_" + item.StudentId})
</td>
DropDownList 助手的第二个参数必须是一个 IEnumerable。
请逐步尝试。
步骤 1)
@Html.DropDownList(
"ListId",
Enumerable.Empty<SelectListItem>(),"<- Select Level ->",
new { style = "width: 360px;" }
)
第 2 步) 您想用来绑定到:
@Html.DropDownList(
"ListId",
Model.PaymentMethodList,"<- Select Level ->",
new { style = "width: 360px;" }
)
步骤 3)
避免让您的 HTML 与您应该使用外部样式的样式混淆 CSS:
@Html.DropDownListFor(
x => x.ListId,
Model.PaymentMethodList,"<- Select Level ->",
new { @class = "mydropdown" }
)
您的外部 Css 代码
.mydropdown{
width: 360px;
}
如果问题仍然存在,请检查您的 css 和脚本或分享更多您的代码。