使用ASP.NET MVC 4 Bootstrap Layout Template(VS2012)

本文详细介绍了如何在Visual Studio 2013中使用Bootstrap3.0的ASP.NET MVC网站项目模板,包括如何在不同版本的Visual Studio中安装和使用模板,以及如何在项目中更新Bootstrap版本,同时提供了模板的选择和安装步骤,帮助开发者快速搭建具备Bootstrap样式的ASP.NET MVC网站。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用 Bootstrap 有一段时间也已经实际用在好几个项目,在之前刚结束的「twMVC - Workshop #1」里带着学员实作的项目也是使用 Bootstrap,Bootstrap 不久前也已经推进到了 3.0 版本,而 VS2013 里所建立的 ASP.NET 专案(新版 ASP.NET)不管是 WebForm 还是 MVC 都已经将项目模板使用 Bootstrap 了,虽然目前在 VS2013 RC 所建立的 ASP.NET 网站模板所使用的 Bootstrap  为 2.3.1 版,不过在 VS2013 的正式发布版本会在项目模板里使用 Bootstrap 3.0。

而在 VS2012 开发网站时,如果要在网站里加入 Bootstrap,除非我们所拿到的网站 prototype 是已经加入了 Bootstrap,不然就是需要我们动手去做,而网络上大多都是介绍如何在一个已经建立好的网站项目里透过 NuGet 加入 Bootstrap,这样的方式也是可以,但如果一开始建立好的网站模板就如同开发 ASP.NET MVC 5 那样,已经套用好 Bootstrap 的 Project Template,这样子就会方便了。

接下来就跟大家简单说明使用「ASP.NET MVC 4 Bootstrap Layout Template (VS2012)」。

在进入主题之前,先跟各位说明一下 VS2013 RC 所建立的 ASP.NET MVC 网站,

 

\
 

预设所建立的网站使用的 Bootstrap 版本为「2.3.1」

 

\
 

执行后的网站内容

 

\
 

可以透过 NuGet 将 Bootstrap 版本更新到 3.0

 

\
 
\

\
 

执行后的网站内容

 

\
 

这边所看到的是网站改用 Bootstrap 3.0 的样子,因为 Project Template 原本是使用 2.3.1,所以套用 3.0 之后所呈现的网页就会看起来怪怪的,不过一开始就有说过,在 VS2013 最后的正式版本发布时,Project Template 将会修改为使用 Bootstrap 3.0。

前面是讲有关 VS2013 里新的 Project Template,然而一般我们在 VS2012 或是在 VS2013 使用 VS2012 的 ASP.NET MVC 开发网站时,预设的 Project Template 是 ASP.NET MVC 4 项目模板,在这个模板里要使用 Bootstrap 就必须手动加入,

VS2012

\
 

VS2013 RC - 开发 VS2012 ASP.NET MVC 4 Web 应用程序

 

\
 

其实我们可以在建立网站的时候可以选择「在线 > 模板」并且搜寻「Bootstrap」,然后在搜寻出来模板里选择使用「ASP.NET MVC 4 Bootstrap Layout Template (VS2012)」,

 

\
 

为何不是选用第一个「ASP.NET MVC 4 with Bootstrap Layout」呢?其实两个 Template 都是同一个作者,只不过「ASP.NET MVC 4 Bootstrap Layout Template (VS2012)」的版本比较新,而且也比要多人使用,

选择项目的模板后就可以建立项目,此时就会立即下载模板所需的档案,当看到以下的「VSIX 安装程序」窗口就选择确定安装「ASP.NET MVC 4 Bootstrap Layout Template (VS2012)」扩充功能,

 

\
 

安装扩充功能后就可以看到 VS2012 开始建立项目,最后就可以看到建立好的项目内容,

 

\

\
 

执行后的网站显示页面

 

\

\
 

就如同我们使用预设的网站项目模板一样,只有基本的支架而已。

此外在刚才从在线模板并建立项目时有安装一个「ASP.NET MVC 4 Bootstrap Layout Template (VS2012)」扩充功能,可以在「工具 > 扩充功能和更新」里看到这一个 Extensions,www.it165.net

 

\
 

这样我们下次要重新建立一个 MVC 网站项目时,可以不必再从在线模板里去安装这个 Project Template,可以直接在「加入新项目 > 已安装的 > Visual C#」里选用「ASP.NET MVC 4 with Bootstrap Layout」这个 Project Template,

 

\
 
Visual Studio 组件库 - ASP.NET MVC 4 Bootstrap Layout Template (VS2012) 扩充功能
http://visualstudiogallery.msdn.microsoft.com/addff204-d297-4f29-9bc4-36256e00c08d
 
\
 

在问答集里已经有人请作者也做个 Bootstrap 3.0 的版本了。

在安装扩充功能时会依据 Visual Studio 版本做筛选,所以就会有另一个给 VS2013 的版本「ASP.NET MVC 4 Bootstrap Layout Template (VS2013)」,这个版本是要给在 VS2013 里开发 Visual Studio 2012 的 ASP.NET MVC 应用程序所用的。

Visual Studio 组件库 - ASP.NET MVC 4 Bootstrap Layout Template (VS2013) 扩充功能
http://visualstudiogallery.msdn.microsoft.com/51802f1f-adac-49ea-a358-5b16f24abd55

在 VS2013 RC 里可以先透过「工具 > 扩充功能和更新」安装「ASP,NET MVC 4 Bootstrap Layout Template (VS2013)」,
 

\
 

接着在「新增项目」里并不是去选择「Web > Visual Studio 2012 > ASP.NET MVC 4 Web 应用程序」,而是要在「已安装的 > 模板 > Visual C#」下去选择「ASP.NET MVC 4 with Bootstrap Layout」,

 

\
 
\
 

选择此项目模板所建立的网站项目就跟在 VS2012 选择同样模板所建立的是一样的。

另外如果不想用这样的方式建立项目,还是习惯用预设的 Project Template 建立项目,然后手动加入 Bootstrap 的话,可以参考「点部落 - 程序宅急便」由 Kyle Shen 所写的文章:

[ASP.NET MVC]新增一个ASP.NET MVC 4的Twitter Bootstrap专案!

选取空白 Project Template 建立 ASP.NET MVC 4 项目,然后在项目里透过 NuGet 加入「Twitter Bootstrap for ASP.NET MVC 4」与「Twitter Bootstrap for ASP.NET MVC 4 Sample」,

\
 
以透过这样的方式为项目加入 Bootstrap。
另外前面已经说过两次,VS2013 最后的正式版本会在 Project Template 改用 Bootstrap 3.0,所以各位开发者朋友们,不管以前有没有使用 Bootstrap 的经验,学习 Bootstrap 3.0 的脚步要加快啰!
Bootstrap (V3.0.0)
Bootstrap GitHub Repository
Bootstrap - Examples
另外目前使用 Bootstrap 2.3.2 的还是占绝大多数,而且周边的一些第三方套件也还没有推出适应 3.0 的版本,所以还是要持续关注 Bootstrap 2.3.2,
Bootstrap (V2.3.2)
另外由微软 MVP - KKBruce 陈传兴所建立的 Bootstrap 中文教学网站也是不能错过的喔!
Bootstrap V2中文教学 - KKBruce
One of the leading open source frontend frameworks, Bootstrap has undergone a significant change and introduced several features that make designing compelling, next-generation UIs much simpler. Integrating Bootstrap with ASP.NET’s powerful components can further enhance its capabilities. This book guides you through the process of creating an ASP.NET MVC website from scratch using Bootstrap. You will learn about the various Bootstrap components as well as techniques to include them in your own projects. The book includes practical examples to show you how to use open source plugins with Bootstrap and ASP.NET MVC and guides you through building an ASP.NET MVC website using Bootstrap, utilizing layout and user interface components. At the end of this book, you will find some valuable tips and tricks to help you get the most out of your Bootstrap- and ASP.NET MVC-integrated website. What You Will Learn Create a new ASP.Net MVC 6 project that uses Bootstrap for its styling and learn how to include external libraries using the new package managers Learn to use the various Bootstrap CSS and HTML elements, and how to use the new Bootstrap 4 grid layout system with ASP.Net MVC Explore the different input groups and implement alerts, progress bars, and badges Explore JavaScript components by illustrating and walking through the process of using JavaScript/JQuery to add interactivity to Twitter Bootstrap components Build your own ASP.Net MVC helpers and tag helpers to reduce the amount of HTML needed to generate Bootstrap elements in your projects Convert a Bootstrap HTML template into a usable ASP.Net MVC project Use the jQuery DataTables plugin with Bootstrap and ASP.Net MVC Learn to include and use the TwitterBootstrapMVC library in an ASP.Net MVC project
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值