gpt4 book ai didi

asp.net - 我可以使用 asp :Button like an Html. ActionLink 吗?

转载 作者:行者123 更新时间:2023-12-02 14:32:39 24 4
gpt4 key购买 nike

我有一个 ActionLink:

    <%: Html.ActionLink("MyAction", "MyAction") %>

我想改用一个按钮。像这样的事情:

    <asp:Button ID="Button1" runat="server" Text="MyAction" />

我需要做什么才能使单击按钮执行与单击 ActionLink 相同的操作?

最佳答案

actionlink 与 Web 表单中的 Hyperlinkbutton 或 Hyperlink 控件相当。它们都在 html 中渲染一个标准的 anchor 元素。所以是的,如果你想让它看起来像一个按钮,你应该在它上面添加一些 css 酱。

<%: Html.ActionLink("MyAction", "MyAction", null, new { @class = "button" } %>

并在 css 文件中:

.button  {
outline: 0;
margin: 0 4px 0 0;
padding: 0 1em;
height: 2em;
text-decoration: none !important;
cursor: pointer;
position: relative;
text-align: center;
display: inline-block;
background-color:Green;
border:1px solid Lime;
}
a.button { color:White;}

注意:我是一名开发人员,因此在设计上遇到了一些挑战。使用 border-left、-right、-bottom 和 -top 可以让它看起来更好。

第一条评论后更新:

其他替代方案,对我来说看起来不太好,是:

<% Using (Html.BeginForm("About", "Home")) {%>

<input type="submit" value="About" />

<% } %>

或者使用 Button 控件:

<form id="Form1" runat="server">

<asp:Button runat="server" ID="sfsf" Text ="Go!" PostBackUrl="/Home/About" />

</form>

关于asp.net - 我可以使用 asp :Button like an Html. ActionLink 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3173651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com