twitter-bootstrap 使用 ASP.NET MVC 4 设置 TwitterBootstrap

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14327107/
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-10-21 16:06:37  来源:igfitidea点击:

Setting up TwitterBootstrap with ASP.NET MVC 4

twitter-bootstrapasp.net-mvc-4

提问by Jordan

This is what I have done so far:

这是我到目前为止所做的:

1) create new ASP.NET MVC 4 project in VS2012.

1) 在 VS2012 中创建新的 ASP.NET MVC 4 项目。

2) select the "internet application" template (which includes membership and entity framework)

2)选择“互联网应用”模板(包括会员和实体框架)

3) test it, it works fine

3)测试它,它工作正常

4) using the package manager, run:

4)使用包管理器,运行:

> Install-Package twitter.bootstrap.mvc4
> Install-Package twitter.bootstrap.mvc4.sample

5) in "_ViewStart.cshtml", change

5)在“_ViewStart.cshtml”中,更改

Layout = "~/Views/Shared/_Layout.cshtml" 

to

Layout = "~/Views/Shared/_BootstrapLayout.basic.cshtml"

Unfortunately, when I run it now, I get the following error:

不幸的是,当我现在运行它时,出现以下错误:

The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_BootstrapLayout.basic.cshtml": "featured".

I'm new to ASP.NET and am not really sure what's going on and why this is happening. Any ideas?

我是 ASP.NET 的新手,并不确定发生了什么以及为什么会发生这种情况。有任何想法吗?

As a second question, once I get this fixed, how can I install a template from http://wrapbootstrap.com? I can't seem to find any instructions for how to do it with ASP.NET.

作为第二个问题,一旦我解决了这个问题,我如何从http://wrapbootstrap.com安装模板?我似乎找不到有关如何使用 ASP.NET 执行此操作的任何说明。

回答by Peter

in your Home/index.cshtml there are sections defined that aren't in the bootstrap layout.

在您的 Home/index.cshtml 中,定义了一些不在引导程序布局中的部分。

either add them to the new layout (see Shared/_Layout.cshtml for how, you're looking for something called featured) or delete them from the index.cshtml.

要么将它们添加到新布局(请参阅 Shared/_Layout.cshtml 了解如何,您正在寻找称为特色的东西)或从 index.cshtml 中删除它们。

For homework look up how to define sections in ASP.MVC

对于作业查找如何在 ASP.MVC 中定义部分

回答by BillH

This is probably too late for the original poster, but I think a better solution is to start with an Empty MVC 4 project. That way, you don't have to delete anything.

这对于原始海报来说可能为时已晚,但我认为更好的解决方案是从 Empty MVC 4 项目开始。这样,您就不必删除任何内容。

1) Start with an empty ASP.NET MVC 4 project.
2) Using the package manager, run:

    install-package twitter.bootstrap.mvc4
    install-package twitter.bootstrap.mvc4.sample

This builds and runs fine on my VS2012.

这在我的 VS2012 上构建并运行良好。

It seems to me that this was the original way the sample code was intended to be installed.

在我看来,这是示例代码的原始安装方式。

回答by Alex_Sotam

In the _BootstrapLayout.basic.cshtmlverify that you have "featured" in the @RenderSection :

_BootstrapLayout.basic.cshtml 中,确认您在@RenderSection中具有“特色”:

<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"/>
    @RenderSection("featured", required: false)
    @Html.Partial("_html5shiv")
</head>