为什么单击“按钮”时没有任何反应? [英] Why does nothing happen when clicking on the "button"?

查看:72
本文介绍了为什么单击“按钮”时没有任何反应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标记是这个(在_Layout.cshtml中):



The markup is this (in _Layout.cshtml):

<button type="button" class="btn btn-default">@Html.ActionLink("Home", "Index", "Home")</button





但是当我点击按钮,没有任何反应(浏览器甚至没有尝试加载不同的页面。)



如果我将其更改为:





But when I click on the button, nothing happens (the browser doesn't even try to load a different page.)

If I change it to this:

<button type="button" class="btn btn-default" onclick="location.href='@Url.Action("About", "Home")'">About</button>





它有效,但当然会失去一些造型(文字颜色)是黑色而不是蓝色)。我会自己解决这个问题。



谢谢!



It works, but of course loses some styling (the text color is black instead of blue). I'll figure that out myself.

Thanks!

推荐答案

我同意,如果使用ActionLink为什么需要添加按钮标记。如果需要按钮样式,那么只有

I agree, if ActionLink is used why there is any need to add button tag. If there is a need to have button style, then only
@Html.ActionLink("Home", "Index", "Home",new{@class="Name"})



添加一个具有相似外观按钮的css的类,否则第二种方法完成工作Sir。

谢谢。 :)


add a class that has the css for a similar looking button, else the second approach does the job Sir.
Thanks. :)


我最后将代码更改为:



I ended up changing the code to this:

<button type="button" class="btn btn-default btn-topbar" onclick="location.href='@Url.Action("Index", "Home")'">Home</button





所以我可以坚持使用Bootstrap使用的CSS。



So I could stick with the CSS that Bootstrap uses.


这篇关于为什么单击“按钮”时没有任何反应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆