-
Book Overview & Buying
-
Table Of Contents
Bootstrap for ASP.NET MVC - Second Edition
By :
If we want our helpers to behave in a manner similar to the built-in ASP.NET MVC HTML Helpers, we need to create an extension method. Extension methods are a technique used to add new methods to an existing class.
Extension methods are a very powerful and intuitive approach to add additional functionality to existing classes and can help you in many ways. You can read more about extension methods on MSDN at http://bit.ly/ExtMethods.
We'll create an extension method to the HtmlHelper class that is represented by a view's HTML property by completing the following steps:
Start by adding a new class file called ButtonExtensions.cs to the Helpers folder in the root of your project.
Change the class type to static. Extension methods need to be declared inside a static class.
Add a new method called BootstrapButton to the class. The first parameter of the method indicates which class the extension extends and must be preceded with the this keyword.
The remaining...
Change the font size
Change margin width
Change background colour