views:

54

answers:

5

Hi, I'm just starting out in ASP.NET MVC (and web applications in general, as I've only really worked on console apps before), and was wondering how to display a link instead of a button for submitting a form? Thanks.

A: 

You need to add an onclick JavaScript event to your hyperlink that submits the form.

Dan Diplo
+1  A: 

I assume you are looking to post the form via a hyperlink. You're not going to find any helpers built into the framework which support this action because it isn't a recommended practice for security reasons. That said, here's an approach with is quite safe and should work for you. jQuery Delete Link With Downlevel Support

Ben Griswold
+3  A: 

<a href="#" onclick="document.forms[0].submit()">Please don't right-click, shift-click, ctrl-click or middle-click this link, or do anything else that seems like an obvious thing to do with links beyond just clicking it, as it's a dummy link pretending to be a submit button</a>

Given the issues of people treating links like links (crazy of them, I know) it may be better to do <span onclick="document.forms[0].submit()">Submit!</span> and then use CSS to give it a pointer cursor.

Jon Hanna
A slightly more general solution w/ JQuery is `$(this).nearest('form').submit()`. There may be more than one form per document.
Ryan
A: 

You may want to consider using CSS to hide the submit button's border and background color (and otherwise style it so it has the appearance of a link) instead, so that your form is still be accessible if JavaScript is disabled.

GWB
A: 

Why not use LinkButton?

Alex
because the use of LinkButtons is frowned upon in MVC
rockinthesixstring
ok, good to know, thanks.
Alex