ASP.NET MVC Programmatically Get a List of Controllers

Using Jon’s suggestion of reflecting through the assembly, here is a snippet you may find useful: using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Web.Mvc; public class MvcHelper { private static List<Type> GetSubClasses<T>() { return Assembly.GetCallingAssembly().GetTypes().Where( type => type.IsSubclassOf(typeof(T))).ToList(); } public List<string> GetControllerNames() { List<string> controllerNames = new List<string>(); GetSubClasses<Controller>().ForEach( type => controllerNames.Add(type.Name)); return … Read more

error with decimal in mvc3 – the value is not valid for field

I just stumbled on this again after 2 years. I thought ASP.NET MVC 5 had solved this but looks like it’s not the case. So here goes how to solve the problem… Create a class called DecimalModelBinder like the following and add it to the root of your project for example: using System; using System.Globalization; … Read more

NuGet Package restore failed for project PROJECT: Unable to find version 2.0.0 of package ‘Microsoft.Net.Compilers’

Based on your error message looks like you are looking for a version that no longer exists and cannot tell which Package source you have selected. I feel like you are looking for version 2.0.0 which is not available in nuget.org repository. The latest one is 2.0.0-rc and it is pre release candidate. Please try … Read more

Discovering Generic Controllers in ASP.NET Core

What happens by default During the controller discovery process, your open generic Controller<T> class will be among the candidate types. But the default implementation of the IApplicationFeatureProvider<ControllerFeature> interface, DefaultControllerTypeProvider, will eliminate your Controller<T> because it rules out any class with open generic parameters. Why overriding IsController() doesn’t work Replacing the default implementation of the IApplicationFeatureProvider<ControllerFeature> … Read more

Can Visual Studio always open ASP.NET pages in Source view, not Design view?

Tools → Options → Web Forms Designer → Start pages in “Source view”. In VS < 2015 it was called HTML Designer. For other extensions you can define specific behaviour by right clicking on a file and selecting Open With. This allows you to set once off or default behaviour for opening more esoteric file … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)