Search code examples
asp.net-mvc-3buttonactionmethod

MVC button click to action


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?


Solution

  • 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:

    $('#buttonId').click(function(){
       document.location = '@Url.Action("MyAction","MyController")';
    });
    

    of course, you'd probably want to use ajax, but this is a basic example.