Has anyone written one? I want it to behave like a link but look like a button. A form with a single button wont do it has I don\'t want any POST.
Here is a VB.NET version with one extra thing, the controller and routes parameters are optional so it can be used without repeating the controller name if it's the same as the current/default controller for the page.
Public Module MvcExtensions
''' <summary>
''' Returns an HTML submit button (enclosed in its own form) that contains the virtual path of the specified action.
''' </summary>
''' <param name="helper">The HTML helper instance that this method extends.</param>
''' <param name="text">Text displayed in the button.</param>
''' <param name="action">Action name.</param>
''' <param name="controller">Optional controller name, using current when null.</param>
''' <param name="routeValues">
''' An object that contains the parameters for a route. The parameters are retrieved
''' through reflection by examining the properties of the object.
''' The object is typically created by using object initializer syntax.
''' </param>
''' <returns>
''' HTML output.
''' </returns>
<Extension()> _
Public Function ActionButton(helper As HtmlHelper, text As String, action As String,
Optional controller As String = Nothing, Optional routeValues As Object = Nothing) As MvcHtmlString
' Validate parameters
If String.IsNullOrEmpty(text) Then Throw New ArgumentNullException("text")
' Get post back URL for action
Dim actionUrl As String = New UrlHelper(helper.ViewContext.RequestContext).Action(action, controller, routeValues)
' Build form tag with action URL
Dim form = New TagBuilder("form")
form.Attributes.Add("method", "get")
form.Attributes.Add("action", actionUrl)
' Add button
Dim input = New TagBuilder("input")
input.Attributes.Add("type", "submit")
input.Attributes.Add("value", text)
form.InnerHtml = input.ToString(TagRenderMode.SelfClosing)
' Return result as HTML
Return MvcHtmlString.Create(form.ToString(TagRenderMode.Normal))
End Function
End Module
Then it can be invoked like the other other MVC controls, with minimum code on the page.
This should really have gone into the core MVC framework from the start; it seems such an obvious requirement. I think buttons are much more intuitive for the user when performing actions which create or change things, rather than links. Links should just navigate to related information (not change anything). If i had a grid I would use ActionLink for any data navigation (e.g. click a product name to goto product page) but only ActionButton for real "actions" like edit and delete.