MVC Routing: Errors Troubleshooting of MVC Routing

Hi Folks,

Since I am exploring MVC these days I have tried to temper MVC with given functionality and encountered an error. I think we should understand why it comes and what exactly is wrong with our code.

Errors

  • Value cannot be null or empty. Parameter name: controllerName
  • The RouteData must contain an item named "action" with a non-empty string value

First: Value cannot be null or empty. Parameter name: controllerName.

I changed the route map collection of the application slightly and kept the controller value blank as shown in the image below:

Method for Registering Routes
Because on each URL hit, it first goes to the Route collection and finds a controller to invoke an action method. When it doesn't find a controller value, it issues such an error.

Second: The RouteData must contain an item named 'action' with a non-empty string value.

I changed the route map collection property of the application slightly and kept the action value blank as shown in the image below:

RouteData Error

New RegisterRoute Method
Because on each URL hit, it first goes to the Route collection and finds a controller to invoke an action method. When it doesn't find an action method name, it issues such an error.
The solution for both the errors is, please set some real value for both of the parameters to run an application expected.
For example I have given the value ” Home1” as the controller name but it doesn't exist in my application, so you may encounter a page 404 not found error as depicted in the image below:

Update in Register Route

Page Not Found Error

I hope that if you confront such an issue then this article will be helpful.

Note: The scenarios mentioned above are some of the possible causes of such an error.

Thanks. To learn more about MVC please go through the following link.

MVC Articles

Enjoy coding and reading.


Similar Articles