Getting controller name twice in URL with ASP.NET MVC

0

Sorry for the noob question, but as you can see, the controller name is appearing twice in the URL and it only works if it is in the URL twice: URL

Here is what my controller looks like: Controller Action

And here is my view:

View

I know it's not my routing because if I create another view, the routing works fine. If I just type http://localhost:50903/users then a blank screen appears. I think that it is returning null due to the try-catch block but when it calls the function, this is what it goes to in UserDao:

User.Dao

And this is the stored procedure it is calling:

Stored Procedure

Please help, I'm going nuts

baby_bird

Posted 2019-04-01T20:41:34.330

Reputation: 1

Answers

0

Did you created area in your application ?. Because if you created area and placed User controller folder within it then you can get controller name twice. And as i can see your URL, it shows that your first Controller name users is in lower case because generally When we create area we name it in lower case most of time.

Users Controller name appearing twice in URL because its included area name in URL as shown below:

routes.MapRoute(
      name: "user_route",
      template: "{area:required}/{controller:required}/{action}/{id?}",
      defaults: new { area = "users", controller = "Users" 
      });

remove area from Route.

routes.MapRoute(
      name: "user_route",
      template: "{controller:required}/{action}/{id?}",
      defaults: new { controller = "Users", action = "Index" 
      });

So by this, your controller name will appear only once in the URL.

Note: It's only useful if you have created an area in your application. If you didn't create area, then let me know we will find another solution for it.

Hope this will help you.
Thank you.

HarshShah

Posted 2019-04-01T20:41:34.330

Reputation: 60

0

I discovered what was wrong. I had to change the name of my controller for it to work properly. My application may have been getting confused because the controller name was the same as the name of a view.

baby_bird

Posted 2019-04-01T20:41:34.330

Reputation: 1