从按钮调用 Html.ActionLink?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33189317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 18:22:47  来源:igfitidea点击:

Call Html.ActionLink from a button?

htmlasp.net-mvctwitter-bootstrap

提问by Ben Junior

How can I call the "Register" ActionLink (The one generated on the standard MVC5 project using VS2013) from a bootstrap button?

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

This is the original code:

这是原始代码:

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

I tried this but obviously it didn't work:

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

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

回答by Burk

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

This should work fine...

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

回答by David Kavalir

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