Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Bootstrap for ASP.NET MVC
Bootstrap for ASP.NET MVC

Bootstrap for ASP.NET MVC: Combine the power of ASP.NET Core with Bootstrap 4 to build elegant, responsive web apps , Second Edition

Arrow left icon
Profile Icon van der Westhuizen
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (1 Ratings)
Paperback Sep 2016 186 pages 2nd Edition
eBook
NZ$14.99 NZ$51.99
Paperback
NZ$64.99
Subscription
Free Trial
Arrow left icon
Profile Icon van der Westhuizen
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (1 Ratings)
Paperback Sep 2016 186 pages 2nd Edition
eBook
NZ$14.99 NZ$51.99
Paperback
NZ$64.99
Subscription
Free Trial
eBook
NZ$14.99 NZ$51.99
Paperback
NZ$64.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Bootstrap for ASP.NET MVC

Chapter 2. Using Bootstrap CSS and HTML Elements

Bootstrap provides a wide range of HTML elements and CSS classes as well as an advanced grid system to aid in laying out your web page designs. These classes and elements include utilities to assist with typography, code formatting, table, and form layouts, to name a few.

All CSS classes and HTML elements, combined with the mobile-first fluid grid system, enable developers to build intuitive web interfaces quickly and easily without having to worry about the nuts and bolts of enabling responsiveness for smaller device screens and styling user interface elements.

In this chapter, we will cover the following topics:

  • The Bootstrap grid system
  • Bootstrap tables and buttons
  • Laying out different Bootstrap forms
  • Enabling ASP.NET MVC scaffolding templates
  • Using images in Bootstrap and configuring the images to be responsive

The Bootstrap grid system

In 2015 Google said "more Google searches take place on mobile devices than on computers in 10 countries including the US and Japan". (http://adwords.blogspot.co.za/2015/05/building-for-next-moment.html) This means that chances are more people are browsing your website with a mobile device than a traditional desktop computer.

The Bootstrap grid system is mobile-first, which means it is designed to target devices with smaller displays and then grow as the display size increases. It uses a 12-column layout with different tiers for each media query range.

Bootstrap Grid components

Think of the Bootstrap grid system as similar to a traditional HTML table. It primarily consists of three components:

  • Containers
  • Rows
  • Columns

Containers

Containers are required in order to use the Bootstrap grid system, and are used to wrap and center the page content and to specify a proper width for the layout. As the name implies, it acts as a container for the grid's rows and...

Bootstrap HTML elements

Bootstrap provides a host of different HTML elements that are styled and ready to use. These elements include the following:

  • Tables
  • Buttons
  • Forms
  • Images

Bootstrap tables

Bootstrap provides default styling for HTML tables with a few options to customize their layouts and behaviors. The default ASP.NET MVC scaffolding automatically adds the .table class name to the table element when generating a List view.

Enabling MVC Scaffolding

In the previous chapter, we created an empty ASP.NET Core project. In order to enable the built-in Visual Studio Scaffolding and because the new ASP.NET's approach is to only add the dependencies you need, we have to manually add the required dependencies to the project by completing the following tasks:

  1. Open the project you created in Chapter 1, Getting Started with ASP.NET Core and Bootstrap 4, in Visual Studio.
  2. Locate the project.json file in the project's root folder and double-click it to edit.
  3. Add or update the following dependencies...

Form layout and elements

Forms make up a large section of most line-of-business applications, and therefore, applying a uniform style to all forms in your web application is not only visually pleasing but also provides your users with a friendlier interface. Bootstrap provides a range of CSS styles to enable you to create visually appealing forms.

Vertical/basic forms

The basic form in Bootstrap always displays its contents in a vertical manner, which means that labels for form <input> elements are displayed above them. With Bootstrap 4, the <fieldset> elements do not have any borders, padding, or margins, and they can be used to wrap inputs into groups by setting the <fieldset> element's class to .form-group. Form elements can also be grouped by placing them inside a <div> element with a class of .form-group.

In the HTML markup that follows, a HTML form will be created using the new ASP.NET Core Tag Helpers containing two Bootstrap form input elements and a submit...

Bootstrap images

Images can be made responsive by setting their class attribute to .img-fluid. This will scale the image in relation to its parent element by setting its maximum width to 100% and height to auto.

You also have the option to shape images with either rounded corners, circles, or with an outer border. This is accomplished by setting the <img> element's class to one of the following Bootstrap classes:

  • img-rounded
  • img-circle
  • img-thumbnail

In the following image, we've displayed a list of employees, and their pictures. The list of employees could be retrieved from a database and passed to the view:

Bootstrap images

The code that achieves the preceding result, which can be viewed in the accompanying sample project for this chapter, is as follows:

@model IEnumerable<Chapter2.Models.EmployeeViewModel> 
<div class="container"> 
    <h2>Employees</h2> 
 
    <div class="row"> 
        @foreach (var item in Model) 
        { 
            &lt...

Bootstrap figures

If you need to display an image or a piece of content with a caption, the <figure> element can be used. The <figure> element is part of the HTML5 spec and is not specific to Bootstrap 4. Bootstrap 4 does, however, provide some helper classes to style the <figure> element appropriately.

For example, the following HTML markup will create a <figure> element containing an image and a caption:

<div class="row"> 
    <div class="col-md-12"> 
        <figure class="figure"> 
            <img src="@Url.Content("~/img/bulb.png")" class="figure-img 
             img-fluid img-rounded" alt="Light bulb"> 
            <figcaption class="figure-caption"> 
                This is a public domain image, available from 
            <code>http://publicdomainarchive.com</code> 
            </figcaption> 
        </figure> 
    </div...

The Bootstrap grid system


In 2015 Google said "more Google searches take place on mobile devices than on computers in 10 countries including the US and Japan". (http://adwords.blogspot.co.za/2015/05/building-for-next-moment.html) This means that chances are more people are browsing your website with a mobile device than a traditional desktop computer.

The Bootstrap grid system is mobile-first, which means it is designed to target devices with smaller displays and then grow as the display size increases. It uses a 12-column layout with different tiers for each media query range.

Bootstrap Grid components

Think of the Bootstrap grid system as similar to a traditional HTML table. It primarily consists of three components:

  • Containers

  • Rows

  • Columns

Containers

Containers are required in order to use the Bootstrap grid system, and are used to wrap and center the page content and to specify a proper width for the layout. As the name implies, it acts as a container for the grid's rows and columns and is a...

Left arrow icon Right arrow icon

Key benefits

  • Updated for Bootstrap 4 and ASP.Net MVC 6, this book shows how to take advantage of the latest new features introduced in both of these industry-leading frameworks
  • Build responsive, mobile-ready apps by combining the power of ASP.NET MVC with Bootstrap
  • Grasp the intricacies of Bootstrap and how to use it with ASP.NET MVC
  • Build your own tools and helpers to assist you in creating ASP.NET MVC Bootstrap sites easily and quickly
  • Master the use of Bootstrap components and plugins with ASP.NET MVC

Description

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. After a primer on the fundamentals of Bootstrap, you will learn your way around and create a new ASP.NET MVC project in Visual Studio. You will move on to 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-integrated and ASP.NET MVC-integrated website.

Who is this book for?

If you are an ASP.NET MVC developer and would like to know how to incorporate Bootstrap into your projects, then this book is invaluable to you. Developers with entry-level experience of ASP.NET MVC development and limited experience with Bootstrap will also benefit from this book.

What you will learn

  • • Create a new ASP.NET MVC 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
  • • 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
  • • Convert a Bootstrap HTML template into a usable ASP.NET MVC project
  • • Use the jQuery DataTables plugin with Bootstrap and ASP.NET MVC

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 30, 2016
Length: 186 pages
Edition : 2nd
Language : English
ISBN-13 : 9781785889479
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Sep 30, 2016
Length: 186 pages
Edition : 2nd
Language : English
ISBN-13 : 9781785889479
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just NZ$7 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just NZ$7 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total NZ$ 136.98
Learning ASP.NET Core MVC Programming
NZ$71.99
Bootstrap for ASP.NET MVC
NZ$64.99
Total NZ$ 136.98 Stars icon
Banner background image

Table of Contents

9 Chapters
1. Getting Started with ASP.NET Core and Bootstrap 4 Chevron down icon Chevron up icon
2. Using Bootstrap CSS and HTML Elements Chevron down icon Chevron up icon
3. Using Bootstrap Components Chevron down icon Chevron up icon
4. Using Bootstrap JavaScript Components Chevron down icon Chevron up icon
5. Creating MVC Bootstrap Helper and Tag Helpers Chevron down icon Chevron up icon
6. Converting a Bootstrap HTML Template into a Usable ASP.NET MVC Project Chevron down icon Chevron up icon
7. Using the jQuery DataTables Plugin with Bootstrap 4 Chevron down icon Chevron up icon
8. Creating Bootstrap 4 ASP.NET MVC Sites Using Visual Studio Code Chevron down icon Chevron up icon
A. Bootstrap Resources Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(1 Ratings)
5 star 0%
4 star 100%
3 star 0%
2 star 0%
1 star 0%
RedDevilMutt Nov 30, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
In most regards, I think this is a 5 star book (more about the 4 star rating later) because:• It covered all the Bootstrap 4 topics I was looking for in a Visual Studio and ASP.NET MVC Core environment. I really appreciated the author sticking with the new "Core" coding conventions. In addition, it covered some very valuable topics that I hadn't expected - like using BS4 with jQuery DataTables.• The code examples not only did a good job with BS4 techniques, but the author also demonstrated some very useful bits of C#-MVC that are great code samples for many projects regardless of using BS. Very useful stuff for someone like me who only has an intermediate skill level (at best) in this area.• The github code for this book was nearly flawless - quite an achievement in our ever changing development environment! I recreated over 90% of the examples in my VS 2015 environment and with only one tiny exception they all worked perfectly.• Overall, I found this book did a great job in providing the help I was looking for - the author clearly knows his stuff. I can readily recommend the book with just a few caveats mentioned below.From my experience with the book, I could honestly only give 4 stars because:• The author says the book is for entry-level people with limited BS to people with advanced ASP MVC experience. I found the author's style very confusing in this regard: sometimes he provides detailed instructions suitable for a beginner and other times it would take a fair degree of experience to follow his guidance.• The code examples on github are flat-out excellent. However, it took me some time to figure out that the using the github code isn't optional, it's essential if you actually want to recreate the examples in your Visual Studio environment. I'd suggest to the author that he should explicitly state the need to use the github code as the book's guidance for recreating the examples is frequently confusing and inadequate.Overall, as a developer with modest experience, I found this to be a very useful book. If you're at my level, it's a somewhat confusing tutorial at times, but otherwise pretty good if you realize you need to work with the github code for most of the exercises. For more experienced ASP.NET MVC developers who are familiar with Bootstrap, I'd suggest a quick read and then using it as a reference for incorporating BS4 in your new Core projects - the author's guidance on a given topic, combined with the github code, should serve well. I wouldn't recommend the book for entry-level programmers.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.