MVC @ Url.Action无效

时间:2015-07-01 07:39:18

标签: c# asp.net-mvc

sudo apt-get install libgc1c2:i386 libexpat1-dev:i386 lib32stdc++6 lib32z1 lib32z1-dev

在FireBug上,我可以看到,但它不会采取这种行动。

<div class="col-xs-6 text-right margin-top-x5">
     <div class="adduser pointer" data-url="@Url.Action("Register","Account")"><span class="glyphicons glyphicons-user"></span>&nbsp;Add New User</div>
</div>

3 个答案:

答案 0 :(得分:1)

如果您希望div可点击,则必须为其提供一些代码,以便在用户点击时执行某些操作。

$(function() {
    $("[data-url]").click(function() {
        location.href = $(this).data("url");
    });
}

或者,只需使用锚点:

 <a class="adduser pointer" href="@Url.Action("Register","Account")">
    <span class="glyphicons glyphicons-user"></span>&nbsp;Add New User</a>

答案 1 :(得分:0)

@Url.Action("Register","Account")应该只打印出特定位置的相应操作的URL。

您需要的是@Html.Action。详细了解here

答案 2 :(得分:0)

您是否可能尝试使用锚点?

<div class="col-xs-6 text-right margin-top-x5">
    <a class="adduser pointer" href="@Url.Action("Register","Account")">
<span class="glyphicons glyphicons-user"></span>&nbsp;Add New User</div>

或者您可以使用Html.ActionLink

<div class="col-xs-6 text-right margin-top-x5"> 
<span class="glyphicons glyphicons-user" />
@Html.ActionLink("Add New User", "Register", "Account", null, new { @class = "adduser pointer" })

相关问题