Url.Action not outputting URL

折月煮酒 提交于 2019-12-24 03:20:55

问题


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 ? :/


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/7597156/url-action-not-outputting-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!