views:

43

answers:

2

I've worked on web forms for a while and am not used to mvc.

Here is what i want to do:

<% if guest tehn %>
    URL.RouteURL("AcccountCreate?login=guest")
<% end if %>

However I can't do this because it says a route with this name has not been created. And I am assuming it would be silly to create a route for this.

+1  A: 
<%= Url.Action("AcccountCreate", new { login = "guest" }) %>

or if you want to generate directly a link:

<%= Html.ActionLink("create new account", "AcccountCreate", new { login = "guest" }) %>

You can also specify the controller:

<%= Html.ActionLink(
    "create new account", // text of the link
    "Acccount", // controller name
    "Create", // action name
    new { login = "guest" } // route values (if not part of the route will be sent as query string)
) %>
Darin Dimitrov
Yup, what Darin said (+1). The error you are getting, user455100, is telling you that the particular overload you are using is expecting the name of a route where you've passed, presumably, your URL.
Andrew Barber
awesome thats alot better, thnx
+1  A: 

That is not really now MVC routing was intended to be used. Better to set your URL like:

AccountCreate/guest

And then have your action accept that parameter

public ActionResult AccountCreate(string AccountName)
{
    //AccountName == guest
    return View();
}

Then you could have a routing entry like:

routes.MapRoute(
    "AccountCreate", // Route name
    "{controller}/{action}/{AccountName}", // URL with parameters
    new { controller = "AccountCreate", action = "Index", AccountName = UrlParameter.Optional } // Parameter defaults
);

However, with that if you create an actionlink with a parameter and no matching route it will create a querystring variable for you.

Dustin Laine