views:

68

answers:

4

The default code that VS generates for HomeController is:

<HandleError()> 
Public Class HomeController Inherits System.Web.Mvc.Controller

    Function Index() As ActionResult
        ViewData("Message") = "Welcome to ASP.NET MVC!"

        Return View()
    End Function

    Function About() As ActionResult
        Return View()
    End Function
End Class

Let's say that I want to create a different URL for the about page without changing the method name. I've tried:

'
' GET: /Home/Aboutblah

But that doesn't work. When I go to http://localhost:1957/Aboutblah, I get a 404 from the ASP .NET server.

Consequently, I was wondering if the "GET " blob of text actually does anything and if it is possible to fiddle with URLs without diving into the ASAX file.

+1  A: 

Look into URL Routing, you should be able to define alternative URLs for the controller actions just fine. :)

Rytmis
+1  A: 

You will need to modify the code that sets up the routes.

If it's just a one-off, you can set up a specific route for this url.

The following would explicitly map url "Home/aboutBlah" to action HomeController.About action and use the standard controller/action route url pattern for any other urls:

RouteTable.Routes.MapRoute("CustomAboutUrl", "Home/aboutBlah", new {controller = "Home", action = "About"});

RouteTable.Routes.MapRoute("Default", "{controller}/{action}");

Dan Malcolm
+3  A: 

Also, you can decorate the method with an attribute:

[ActionName("Aboutblah")]

James

EDIT I just noticed you're using VB. You'll have to translate into VB, maybe:

<ActionName("Aboutblah")>

?

Also, yes, the comments, ie:

' Get /Home/Index

are just that -- comments.

James S
A: 

The easiest method would be create a function in the Controller called AboutBlah. You know, like this:

Public Function AboutBlah() AS ActionResult
    return View()
End Function

Then you could have a View named AboutBlah.

No need to set up a route or decorate a function by using an attribute. You could even delete the About function or set it up to bring the AboutBlah view like this:

return View("AboutBlah")
Cyril Gupta