Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a MVC route to a specific controller?

Tags:

asp.net-mvc

My mind is somehow blank. How do I do this:

I have a RegistrationController and want the URL /register to hit the action Register on that controller. What do I have to add as a map route in global.asax?

like image 795
Alex Avatar asked May 31 '09 18:05

Alex


People also ask

How do I add a controller to my route?

Basic Controllers You can define a route to this controller method like so: use App\Http\Controllers\UserController; Route::get('/user/{id}', [UserController::class, 'show']);

Which method is used for adding routes to an MVC application?

When an MVC application first starts, the Application_Start() method is called. This method, in turn, calls the RegisterRoutes() method. The RegisterRoutes() method creates the route table. The default route table contains a single route (named Default).

How are URL patterns mapped to a handler in ASP.NET MVC?

Typical URL Patterns in MVC Applications URL patterns for routes in MVC Applications typically include {controller} and {action} placeholders. When a request is received, it is routed to the UrlRoutingModule object and then to the MvcHandler HTTP handler.

What is custom routing in MVC?

In the custom routing mode MVC sites respond to incoming requests using standard ASP.NET routing. Page URLs are determined by the routes that you register into your MVC application's routing table.


1 Answers

Actually, what you want is this:

routes.MapRoute(
            "RegisterRoute",
            "Register",
            new { controller = "Registration", action = "Register" }
        );

Now you can go to your page with an url like:

http://www.yoursite.com/register

like image 179
Gerardo Contijoch Avatar answered Oct 07 '22 00:10

Gerardo Contijoch