Url.Action不输出网址

Cam*_*ron 2 asp.net-mvc razor

我正在使用Url.Action,因此我可以创建更复杂的HTML链接,因为ActionLink不允许在其中使用HTML.例:

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

但是URL没有出现在href?有什么想法吗?:/

arc*_*hil 6

你正在使用Url.Action的这个重载

public string Action(
    string actionName,
    string controllerName,
    Object routeValues,
    string protocol
)
Run Code Online (Sandbox Code Playgroud)

你肯定使用它错了(没有像"创建"这样的协议).为您使用任何适当的重载.举例来说,如果你有OrganizationsControllerCreate行动,这段代码将是不够的:

@Url.Action("Create", "Organisations")
Run Code Online (Sandbox Code Playgroud)

如果要路由到另一个区域,请提供routeValues对象new {Area = "anotherAreaName"}.

@Url.Action("Create", "Manage", new {Area = "Organizations"})
Run Code Online (Sandbox Code Playgroud)

这将路由到Organizations区域,在ManageController上创建操作