tags:

views:

44

answers:

1

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" />

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

+1  A: 

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" } %>

and in the css file:

.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;}

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

Update after the first comment:

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

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

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

<% } %>

Or with the Button control:

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

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

</form>
XIII
Is there no way to use the actual button control to trigger the action?
ESRogs
Ah, that last one with the PostBackUrl is what I was trying to do. I think I had just been getting the url wrong. This works for me now. Thanks!
ESRogs