【问题标题】:Call Html.ActionLink from a button?从按钮调用 Html.ActionLink?
【发布时间】:2016-01-16 07:38:45
【问题描述】:

如何调用“注册”ActionLink(在标准 MVC5 上生成的 使用 VS2013 的项目)从引导按钮?

这是原始代码:

@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })

我试过了,但显然没有用:

<button type="button" class="btn btn-info" onclick="window.location.href('@Url.Action("Register", "Account")')">Add New User</button>

【问题讨论】:

  • 为什么你不使用正确类的锚? @Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink", @class="btn btn-info btn-link" }) 应该可以工作并且应该是也可以作为按钮可见。
  • 完美。它工作得很好。我投了赞成票。

标签: html asp.net-mvc twitter-bootstrap


【解决方案1】:
<input type="button" class="btn btn-info" value="Let's Go!" onclick="location.href='@Url.Action("Action", "Controller")'" />

这应该可以正常工作...

【讨论】:

  • 可以在新标签页打开吗?
【解决方案2】:
@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { @class = "btn btn-primary", @role="button" })  

【讨论】:

  • 欢迎来到 StackOverflow。请注意,第一个帖子经过彻底审核,以便将您介绍给社区。请在您的答案中添加解释 - 为什么问题中的行不起作用,以及您的建议实际上改进了什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-24
  • 2019-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多