You want to perform some dynamic processing in your code and you need to determine either the name of the current controller or the current action or both. Enter the object ControllerContext.RouteData.
Category: ASP.NET
-
C# HtmlExtension to display SVGs
You have SVGs that you wish to display on your website but you want to be able to re-use them without copying and pasting the code or creating a shared view.
By creating an HtmlExtension class with a function called Svg you can create a centralized place to store and re-use your SVGs.
-
C# Improving string.IsNullOrEmpty readability
I often find myself using this great C# function: string.IsNullOrEmpty. It is the assured way to confirm whether a string is empty – null or otherwise. However, I often find myself wanting to know when it is not empty, so I wrote an string extension named HasValue.
-
C# OutputCache with subdomains
The other day I was working on a project that was leveraging OutputCache. This little attribute is a fantastic way to implement caching in an MVC project. This was working great until I encountered a snag when using a subdomain.
-
Unit Testing Data Validation with MVC
You’ve added some data validation and you want to test it out in action. The data validation can be standard data annotations, custom data attributes, or data validation implemented via an IValidatableObject. This article will explore how to leverage the ValidationContext to execute and assert the test results.