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 then %>
    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.

2 Answers 2

3
<%= 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)
) %>
Sign up to request clarification or add additional context in comments.

2 Comments

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.
awesome thats alot better, thnx
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.