O'Reilly logo

Bootstrap for ASP.NET MVC by Pieter van der Westhuizen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating fluent HTML helpers

Fluent interfaces is a technique used in software development to implement an object-orientated API in such a manner that it provides more readable code, and it is usually implemented using method chaining.

Note

The term "fluent interface" was first used by Eric Evans and Martin Fowler. If you'd like to learn more about fluent interfaces, read Martin Fowler's blog post available at http://bit.ly/FluentInterfaces.

We'll create an HTML helper that will help us render Bootstrap alerts with a single line of code. The helper will take a fluent interface approach, which means that we'll be able to render a dismissible, warning alert box using the following line of code:

@Html.Alert("This is a warning").Warning().Dismissible() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required