Possible Duplicate:
Mvc Html.ActionButton
With ASP.NET MVC 3
I know how to create a link to an action method very easily but what I'd like to know is how do you make a button (when clicked) call a particular action method?
Possible Duplicate:
Mvc Html.ActionButton
With ASP.NET MVC 3
I know how to create a link to an action method very easily but what I'd like to know is how do you make a button (when clicked) call a particular action method?
Sachin,
If you're using jquery (which you don't mention but I'll show as it's fairly standard with mvc), you'd do the following:
of course, you'd probably want to use ajax, but this is a basic example.
How do you do it? The same way you would if not using MVC.
You could use an html
<form>
:As well as Darin's answer about using a form GET method, you can also call javascript functions that will then in turn call an action.
You can intercept the button click event when clicked and run your own code. That code can call an action asynchronously using Ajax or just simply navigate to an action method
Here's sample javascript that intercepts the button click event
Or you can intercept a button that has an href attribute
This adds parameter information that you may have stored in another input on the page and appends it to the Url and then navigates to the action