Home » ASP » ASP.MVC » An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

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

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";

If you like my article, think to buy my annual book, professionally edited by a proofreader. directly from me or on Amazon. I also wrote a TypeScript book called Holistic TypeScript

One Response so far.

  1. Muhammad Umar Sultan Sheikh says:

    This solution made my life easy, I was facing this issue since 45 hours and after implementing that solution i am able to execute my code.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.