[英]MVC @Url.Action not working
<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> Add New User</div>
</div>
在FireBug上,我可以看到但不会执行该操作。
<div class="adduser pointer" data-url="/Account/Register">
如果希望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> Add New User</a>
@Url.Action("Register","Account")
应该仅在特定位置打印出相应操作的URL。
您需要的是@Html.Action
。 在这里了解更多
您是否可能尝试使用锚点?
<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> 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" })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.