我可以使用一个asp:按钮像一个Html.ActionLink? [英] Can I use an asp:Button like an Html.ActionLink?

查看:145
本文介绍了我可以使用一个asp:按钮像一个Html.ActionLink?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ActionLink的:

I have an ActionLink:

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

我想用一个按钮来代替。事情是这样的:

I would like to use a button instead. Something like this:

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

什么我需要做的,使点击按钮执行相同的操作,点击ActionLink的?

What do I need to do to make clicking the button perform the same action as clicking the ActionLink?

推荐答案

该ActionLink的将是相当媲美Hyperlinkbutton或超链接控件web表单。他们都在渲染HTML标准的锚元素。所以,是的,如果你想使它看起来像一个按钮,你应该在它的上面添加一些CSS酱。

The actionlink would be rather comparable to Hyperlinkbutton or Hyperlink controls in webforms. They all render a standard anchor element in html. So yes if you want to make it look like a button you should add some css sauce on top of it.

<%: 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;}

请注意:我是一名开发人员,所以有些设计挑战。与左边框,右汉字,汉字玩耍和-TOP你可以使它看起来更好。

Note: I'm a developer so somewhat design challenged. Playing around with border-left, -right, -bottom and -top you can make it look nicer.

第一个注释后更新:

其他选择,这不看那个对我很好,分别是:

Other alternatives, which don't look that nice to me, are:

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

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

<% } %>

或者与Button控件:

Or with the Button control:

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

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

</form>

这篇关于我可以使用一个asp:按钮像一个Html.ActionLink?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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