Question

I have a HTML form, and I have a Controller Action that accepts the POST request. Everything works with a regular submit button, but I would like to submit the form with a link (<a>-tag) instead, to be able to further control the formatting. Is there any way of doing this nicely built into the ASP.NET MVC Framework, or should I write my own extension method? Is it even possible to do this without javascript (I will use AJAX in the future, but it has to work without).

Was it helpful?

Solution

Here is a complete example. Note that this particular example does something fairly important: it has a fallback for browsers with JavaScript disabled.

OTHER TIPS

If javascript and jQuery is enabled this effectively replaces all submit-buttons with links:

$("input:submit").hide().each(function (index, Element) {
    var elm = $(Element);
    elm.after($("<a href=#>" + elm.val() + "</a>")
            .click(function () { elm.click(); })
        );
});

Based on post linked to in the accepted answer.

I'm not aware of a helper and as far as I know it is impossible to submit a form using an anchor tag without using javascript.

You cannot 'submit a form' using a link (<a> tag) without Javascript. The javascript is going to generate a standard POST request (same as clicking a submit form button) behind the scenes.

There are other workarounds for those with JS disabled, look at what @Craig Stuntz submitted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top