I have a single form on my page with two ways of submitting it. The first is an anchor tag and the other is a submit button, both of them having different behaviours.
How can I assign to each a separate action method? Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It really depends on what the anchor tag does – presumably it’s triggering a submit in javascript?
If it’s actually just doing a
GETinstead of aPOST, then you can do as @dbaseman suggests – have separate action methods for the two request types.But if the anchor does javascript submit, then my preference would be to simply give the submit button a name so you can detect it on the server in one action method, and then fork the code from there:
And then your action method:
Even better you can use a
<button>instead, and then you can divorce the displayed text from the value that the button submits (useful if you’re localising the page):Now you can have a
submitMethodparameter on your action method, in which you look for'fromButton'.Either way – the anchor tag/javascript (if that’s how you’re doing it) won’t submit this value, because the button’s value is only submitted when it’s clicked.