<formmethod="get"action="/myController/myAction/"> <inputtype="submit"value="button text goes here"/> </form>
In response to cdmckay's answer, here's an alternative code that uses the TagBuilderclass instead of a regular StringBuilder to build the form, mostly for clarity.
using System.Web.Mvc; using System.Web.Mvc.Html; using System.Web.Routing; namespace MvcApplication1 { publicstaticclassHtmlExtensions { publicstaticstring ActionButton(thisHtmlHelper helper, string value, string action, string controller, object routeValues) { var a = (newUrlHelper(helper.ViewContext.RequestContext)) .Action(action, controller, routeValues); var form = newTagBuilder("form"); form.Attributes.Add("method", "get"); form.Attributes.Add("action", a); var input = newTagBuilder("input"); input.Attributes.Add("type", "submit"); input.Attributes.Add("value", value); form.InnerHtml = input.ToString(TagRenderMode.SelfClosing); return form.ToString(TagRenderMode.Normal); } } }
I am aware that there might be quite a lot of overhead in this code, but I am expecting that you won't need to run it a lot of times on each page. In case you do, there is probably a bunch of optimizations that you could do.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Submit button:
In response to cdmckay's answer, here's an alternative code that uses the TagBuilder class instead of a regular StringBuilder to build the form, mostly for clarity.
I am aware that there might be quite a lot of overhead in this code, but I am expecting that you won't need to run it a lot of times on each page. In case you do, there is probably a bunch of optimizations that you could do.