Cameron
Cameron

Reputation: 28783

Url.Action not outputting URL

I'm using Url.Action so that I can create more complex HTML links as ActionLink doesn't allow HTML inside them. Example:

 <a class="uiButton" href="@Url.Action("Areas","Organisations","Manage","Create")" title="New Organisation">
                    <span class="icon organisations-new">New Organisation</span>
                </a>

However the URL doesn't appear in the href? Any ideas why ? :/

Upvotes: 2

Views: 4001

Answers (2)

Dani
Dani

Reputation: 2036

In my case I had an empty string because "area" parameter was wrong.

Upvotes: 1

archil
archil

Reputation: 39491

You are using this overload of Url.Action

public string Action(
    string actionName,
    string controllerName,
    Object routeValues,
    string protocol
)

And you are definitely using it wrong (no protocol like "Create"). Use any of appropriate overloads for you. For example, if you've got OrganizationsController and Create action, this code will be enough:

@Url.Action("Create", "Organisations")

If you want to route to another area, supply routeValues object like new {Area = "anotherAreaName"}.

@Url.Action("Create", "Manage", new {Area = "Organizations"})

This will route to Organizations area, Create action on ManageController

Upvotes: 6

Related Questions