C# 如何解决 MVC4 Twitter Bootstrap 项目从 VS2012 中的简单 Nuget 安装失败的问题?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19618771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 15:26:19  来源:igfitidea点击:

How to resolve MVC4 Twitter Bootstrap project fail from simple Nuget installations in VS2012?

c#asp.net-mvcasp.net-mvc-4twitter-bootstraptwitter

提问by ElHaix

I'm having an issue with launching a MVC4 application with the Twitter bootstrap.

我在使用 Twitter 引导程序启动 MVC4 应用程序时遇到问题。

In VS 2012, I created a new empty MVC4 application, installed the following packages:

在 VS 2012 中,我创建了一个新的空 MVC4 应用程序,安装了以下包:

  • Install-Package twitter.bootstrap.mvc4
  • Install-Package twitter.bootstrap.mvc4.sample
  • 安装包 twitter.bootstrap.mvc4
  • 安装包 twitter.bootstrap.mvc4.sample

Seems like some navigation route options-related issues, as I am going through these few turorials Link 1and Link 2.

似乎是一些与导航路线选项相关的问题,因为我正在浏览这些少数教程Link 1Link 2

In reading the note about possible compile issues, I restarted the solution, but errors I'm receiving aren't the ones in the readme and are focused around the NavigationRouteOptions, NavigationRouteFilters, RouteValueDictionary, FilterTokenand HasFilterToken:

在阅读有关可能的编译问题的说明,我重新启动了解决方案,但我收到的错误是不是自述的那些和围绕集中在NavigationRouteOptionsNavigationRouteFiltersRouteValueDictionaryFilterTokenHasFilterToken

'System.Web.Routing.RouteValueDictionary' does not contain a definition for 'HasFilterToken' and no extension method 'HasFilterToken' accepting a 
first argument of type 'System.Web.Routing.RouteValueDictionary' could be found (are you missing a using directive or an assembly reference?)   
...\AdministrationRouteFilter.cs    18  

'System.Web.Routing.RouteValueDictionary' does not contain a definition for 'FilterToken' and no extension method 'FilterToken' accepting a 
first argument of type 'System.Web.Routing.RouteValueDictionary' could be found (are you missing a using directive or an assembly reference?)   
..\AdministrationRouteFilter.cs 20  

The name 'NavigationRouteFilters' does not exist in the current context 

'NavigationRouteOptions' could not be found (are you missing a using directive or an assembly reference?)

I have confirmed that I do have navigationroutes.mvc4Nuget package installed as well.

我已经确认我也安装了navigationroutes.mvc4Nuget 包。

Is this only working in VS 2013?

这仅适用于 VS 2013 吗?

The Nuget packages are dated October 26, 2013.

Nuget 软件包的日期为 2013 年 10 月 26 日。

Assistance appreciated.

帮助表示赞赏。

采纳答案by Muthu

It seems there is already a discussion about the error in github

github上好像已经有人讨论过这个错误了

try uninstalling 1.1.100 and install 1.0.90 versions in the following order.

尝试卸载 1.1.100 并按以下顺序安装 1.0.90 版本。

  • PM> Install-Package twitter.bootstrap.mvc4.sample -Version 1.0.90
  • PM> Uninstall-Package twitter.bootstrap.mvc4.htmlhelpers -Force
  • PM> Install-Package twitter.bootstrap.mvc4.htmlhelpers -version 1.0.90
  • PM> Uninstall-Package twitter.bootstrap.mvc4 -Force
  • PM> Install-Package twitter.bootstrap.mvc4 -version 1.0.90
  • PM> 安装包 twitter.bootstrap.mvc4.sample -Version 1.0.90
  • PM> 卸载包 twitter.bootstrap.mvc4.htmlhelpers -Force
  • PM> 安装包 twitter.bootstrap.mvc4.htmlhelpers -version 1.0.90
  • PM> 卸载包 twitter.bootstrap.mvc4 -Force
  • PM> 安装包 twitter.bootstrap.mvc4 -version 1.0.90

回答by Pablo Contreras

Good morning fellas, i have run into the exact same issue, and at least for me, this worked>

早上好,伙计们,我遇到了完全相同的问题,至少对我来说,这有效>

instead of installing twetter.bootstrap, just install the bootstrap package, because it looks like with the release of vs2013, they just handed the package over, to MS maintenance.

不用安装twetter.bootstrap,直接安装bootstrap包,因为好像是vs2013的发布,他们只是把包交给MS维护。

so, uninstall your current bootstrap version, (the twitter one) and just install general bootstrap. (or be sure to be installing version 3.0.2)

因此,卸载您当前的引导程序版本(Twitter 版本)并安装通用引导程序。(或者一定要安装 3.0.2 版)

install-package bootstrap

note that this fix, applies to VS2k12.

请注意,此修复适用于 VS2k12。

回答by Ali A

Muthu's solution works if you create an VS2012 project (Basic --- NOT the Internet!), then add the css files in the bootstrapLayout.basic.cshtml (which you will find in the shared folder) and add the Javascript files at the bottom of bootstrapLayout.basic.cshtml. Here is my bootstraplayout.basic.cshtml. Note... the order of the script files is important (Good luck!) ... and THANKS Mithu!

如果您创建一个 VS2012 项目(基本 --- 不是 Internet!),然后在 bootstrapLayout.basic.cshtml(您将在共享文件夹中找到)中添加 css 文件并在底部添加 Javascript 文件,则 Muthu 的解决方案有效bootstrapLayout.basic.cshtml 的。这是我的 bootstraplayout.basic.cshtml。注意...脚本文件的顺序很重要(祝你好运!)...感谢 Mithu!

@using System.Web.Optimization
@using BootstrapSupport
@using NavigationRoutes
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>@ViewBag.Title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        @*<link href="@Styles.Url("~/content/css")" rel="stylesheet"/>*@
 @*   @Styles.Render("~/Content/bootstrap.min.css")
    @Scripts.Render("~/bundles/modernizr")*@
        <link href="~/Content/body.css" rel="stylesheet" />
        <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
        <link href="~/Content/bootstrap-responsive.min.css" rel="stylesheet" />
        @RenderSection("head", required: false)
        @Html.Partial("_html5shiv")
        @* favicons and touch icons go here *@
    </head>
    <body>
        <div class="navbar navbar-inverse navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container">
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </a>
                    <a class="brand" href="#" title="change in _bootstrapLayout.basic.cshtml">Application Name</a>
                    <div class="nav-collapse collapse">
                        <ul class="nav">
                            @Html.Navigation()
                        </ul>
                    </div>
                </div>
            </div>
        </div>        
        <div class="container">
            @Html.Partial("_alerts")
            @Html.Partial("_validationSummary")
            @RenderBody()   
            <hr>
            <footer>
                <p>&copy; Company @System.DateTime.Now.ToString("yyyy")</p>
            </footer> 
        </div>
         @*@Scripts.Render("~/js")*@
        <script src="~/Scripts/jquery-1.9.1.min.js"></script>
        <script src="~/Scripts/jquery-ui-1.8.24.min.js"></script>
        <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
        <script src="~/Scripts/jquery.validate.min.js"></script>
        <script src="~/Scripts/jquery.validate.unobtrusive-custom-for-bootstrap.js"></script>
        <script src="~/Scripts/knockout-2.2.0.js"></script>
        <script src="~/Scripts/bootstrap.min.js"></script>

         @RenderSection("Scripts", required: false)
    </body>
</html>

回答by Iwona Kubowicz

For me this tutorial about how to setup ASP.NET MVC 4 and Twitter Bootstrap works fine: https://www.macaw.nl/weblog/2013/5/setting-up-a-solution-with-mvc4-and-twitter-bootstrap

对我来说,本教程关于如何设置 ASP.NET MVC 4 和 Twitter Bootstrap 工作正常:https: //www.macaw.nl/weblog/2013/5/setting-up-a-solution-with-mvc4-and-twitter -引导程序