【发布时间】:2017-03-10 10:38:36
【问题描述】:
我很确定我的问题与脚本参考有关。
我已将其添加到我的捆绑包中
bundles.Add(new ScriptBundle("~/bundles/bootstrap-select").Include(
"~/Scripts/bootstrap-select.js",
"~/Scripts/bootstrap-select.min.js"));
这是我的观点代码:
<script type="text/javascript">
$(document).ready(function () {
$('.selectpicker').selectpicker({
liveSearch: true,
showSubtext: true
});
});
HTML 格式:
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.SagId, "SagId", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(x => x.SagId,(IEnumerable<SelectListItem>)ViewBag.SagId,
new
{
@class = "form-control selectpicker",
data_show_subtext = "true",
data_live_search = "true"
})
@Html.ValidationMessageFor(model => model.SagId, "", new { @class = "text-danger" })
</div>
</div>
我从我的视图包中获取了列表,它工作正常。但我似乎无法解决这个问题。
更新: 试图在视图中手动添加引用。现在保管箱完全消失了,我得到了这些错误:
Uncaught TypeError: Cannot read property 'valHooks' of undefined
at bootstrap-select.min.js:7
at bootstrap-select.min.js:8
at bootstrap-select.min.js:7
at bootstrap-select.min.js:7
Create:78 Uncaught ReferenceError: $ is not defined 创建时:78
【问题讨论】:
-
什么问题不能解决?
-
它不会将样式/javascript 应用到我的下拉列表中。
-
我希望它看起来像这样:jsfiddle.net/codeandcloud/a5r2vyu2/1
-
你没有包含任何样式信息,这个问题中的代码和你的问题完全无关
-
@Liam 我现在刚刚添加了一些,我的问题是我无法将“selectpicker”样式应用于我的 DropDownBox。
标签: javascript asp.net-mvc bootstrap-selectpicker