-4

i am working on a web project in asp.net mvc. This is code in my RouteConfig

This is url

localhost:55960/Home/myAction/80102/Aus-won-the-match-by-9-wickets

but i want to make it like

localhost:55960/myAction/80102/Aus-won-the-match-by-9-wickets

 routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}/{id}/{Title}",
                    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, Title = "" }
                );

I have applied many suggestions available on this platform but not worked. Is there any one who can explain in detail

Fiaz Khan
  • 5
  • 1
  • What is the motivation behind your question? Are you trying to obfuscate the code-level name of a controller or are you trying to simplify the URL as per Isaack Rasmussen's answer? – camelCase Aug 16 '17 at 14:14
  • this is your answer: https://stackoverflow.com/questions/57799273/how-to-remove-controller-name-from-url-in-mvc-project/57799331#57799331 – Pritesh Sep 07 '19 at 04:51

1 Answers1

1

So you want your controller to be at the root, like domain.com/?id=1 or domain.com/list?id=1 instead of domain.com/controller/list?id=1 ?

You can add to your config

config.MapHttpAttributeRoutes();

Then for that controller,

[RoutePrefix("")]
public class HomeController : Controller

But this may get confusing to keep track of if you have many controllers. And it may be better to configure routes.MapRoute() to point to a default controller

Isaack Rasmussen
  • 457
  • 4
  • 11