如何与MVC 5中的Bootstrap正确合作?
我立即为我的英语表示歉意,请帮助我弄清楚如何在MVC5应用程序中使用Bootstrap下拉元素?
该问题的本质如下,在MVC 5上有一个应用程序,它具有一个带有下拉元素的按钮,但它不起作用,这是Bundleconfig代码,
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*",
"~/Scripts/messages_ru.js",
"~/Scripts/methods_ru.js",
"~/Scripts/jquery.options.validate.js"
));
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/css/Styles.css",
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/newStyle.css"
));
bundles.Add(new ScriptBundle("~/bundles/jquery-ui").Include(
"~/Scripts/jquery-ui-1.11.4.js",
"~/Scripts/v2/jquery-1.9.1.min.js",
"~/Scripts/jquery.maskedinput.min.js",
"~/Scripts/jquery.maskedinput.add.js",
"~/Scripts/select2.js",
"~/Scripts/jquery.multiple.select.js",
"~/Scripts/jquery-ui.datepicker.add.js"
));
}
}
这是按钮本身的代码
<button class="button dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Button_1
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
@foreach (var type in Enum.GetValues(typeof(REPORT_TYPE)).Cast<REPORT_TYPE>())
{
<li><a class="dropdown-item" href="#">@type.GetDescription()</a></li>
}
</ul>
,此处 是查看的代码脚本连接代码是否在同一视图中
<script src="~/Scripts/bootstrap.bundle.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
,但是当您单击按钮时,列表不打开,谁能告诉我我犯了什么错误?
更新1: 如果您连接以下脚本,则一切正常,但是它们是为Bootstrap设计的,我需要5个版本
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
Immediately I apologize for my English, please help me figure out how to work with the bootstrap drop-down element in an MVC5 application?
The essence of the question is as follows, there is an application on MVC 5, it has a button with drop-down elements, but it does not work, here is the BundleConfig code
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*",
"~/Scripts/messages_ru.js",
"~/Scripts/methods_ru.js",
"~/Scripts/jquery.options.validate.js"
));
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/css/Styles.css",
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/newStyle.css"
));
bundles.Add(new ScriptBundle("~/bundles/jquery-ui").Include(
"~/Scripts/jquery-ui-1.11.4.js",
"~/Scripts/v2/jquery-1.9.1.min.js",
"~/Scripts/jquery.maskedinput.min.js",
"~/Scripts/jquery.maskedinput.add.js",
"~/Scripts/select2.js",
"~/Scripts/jquery.multiple.select.js",
"~/Scripts/jquery-ui.datepicker.add.js"
));
}
}
Here is the code of the button itself in View
<button class="button dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Button_1
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
@foreach (var type in Enum.GetValues(typeof(REPORT_TYPE)).Cast<REPORT_TYPE>())
{
<li><a class="dropdown-item" href="#">@type.GetDescription()</a></li>
}
</ul>
And here is the script connection code in the same View
<script src="~/Scripts/bootstrap.bundle.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
But when you click on the button, the list does not open, who can tell me what I made a mistake?
Update 1:
If you connect the following scripts, then everything works fine, but they are designed for Bootstrap 4 versions, and I need for 5
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论