If you have spent much time around ASP.NET MVC, you have no doubt used ModelState just like all other good little MVC developers. Have you ever peeked under the covers, though, and looked at why and how it works? In this post, we will do just that. What is ModelState? ModelState is, at its core, the values of a form …
An Introduction to the AntiForgeryToken HTML Helper
The ASP.NET MVC AntiForgeryToken HTML Helper is a widely used but not well-understood helper. In this post, I will look at the details of the helper, explain how it works, and how you should be using it. What is the AntiForgeryToken Helper? The AntiForgeryToken helper protects your site from cross-site request forgery. Cross-site request forgery is the process …
A Beginner’s Guide to Creating Custom ASP.NET MVC HTML Helpers
Introduction As a beginner, creating your own custom HTML Helpers might seem a bit daunting but it doesn’t have to be. Eventually, they boil down to simple HTML that all web developers are familiar with. In fact, HTML Helpers are very easy to create and the difficulty scales directly with the complexity of the problem you are trying to solve …
Beginner’s Guide to Using Log4NET in an ASP.NET MVC Application
Logging is an integral part of any application. There are many options and not all of them good. Log4NET is a great framework for both simple and extremely complex scenarios, allowing you to choose the log format, the storage medium, and custom rules for messages and levels. Creating new message handlers is an easy process and Log4NET can be configured …
ASP.NET MVC Bundling and Minification for Beginners
Starting in version 4, ASP.NET MVC has been capable of bundling script and style files and minifying them to help make sites faster. Bundling and minification is not a black box. Its easy to see what is going on using only your browser. The image below is a default MVC application that has not been bundled. Without Bundling and …
Using SignalR in an ASP.NET MVC Application
SignalR is a real-time communication framework from Microsoft. SignalR can be used for communications between the server and client and between clients by using the server as a go between. In this post, I will show you how to create yet another chat application (there are many already out there using SignalR) but I will look at some of the …
The Case Against Self-Aware ViewModels in ASP.NET MVC
ViewModels in ASP.NET MVC are a valuable tool and are widely considered a best practice in developing MVC applications. In this post, I will make a case for why ViewModels should NOT be self-aware. ViewModels are a commonly used mechanism to deliver everything a View needs in a single object. Without them, you would have to push them to the …
Using Unity in ASP.NET MVC 5 in Less than 5 Minutes
Unity is a dependency injection framework built by the Pattern and Practices team at Microsoft. In this post, I will give you a quick overview of implementing Unity into an ASP.NET MVC project very quickly. What is Unity? Unity is a very nicely integrated library from Microsoft that has both configuration-based and code-based dependency injection options. In this post, I …
Using Ninject in ASP.NET MVC 5 in Less than 5 Minutes
Ninject is a great Dependency Injection framework and works wonderfully with ASP.NET MVC 5. In this post, I will show you how to get Ninject running in a MVC project in less than 5 minutes. What is Ninject? Ninject is a light weight, versatile dependency injection framework that can be used in .NET applications. It allows you to focus on …