从按钮调用Html.ActionLink?

Ben*_*ior 12 html asp.net-mvc twitter-bootstrap

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

这是原始代码:

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

我试过这个,但显然它不起作用:

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

Bur*_*urk 23

<input type="button" class="btn btn-info" value="Let's Go!" onclick="location.href='@Url.Action("Action", "Controller")'" />
Run Code Online (Sandbox Code Playgroud)

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


小智 6

@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { @class = "btn btn-primary", @role="button" })  
Run Code Online (Sandbox Code Playgroud)

  • 欢迎使用 StackOverflow。请注意,第一篇帖子经过彻底审核,旨在向您介绍社区。请为您的答案添加解释 - 为什么问题中的行不起作用,以及您的建议实际上改进了什么。 (5认同)