An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type<!-- --> | <!-- -->Patrick Desjardins Blog
Patrick Desjardins Blog
Patrick Desjardins picture from a conference

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

Posted on: November 9, 2012

If you are trying to use a static string in an attribute for an action inside a Asp.Net MVC's controller, you will get a strange error.

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

This is because you are using static string instead of constant.

public static string AdministratorRole="admin";

The code below works because it's a public const string instead of a public static string.

public const string AdministratorRole="admin";