Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC button click to action [duplicate]

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?

like image 585
Sachin Kainth Avatar asked May 25 '12 11:05

Sachin Kainth


1 Answers

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.

like image 61
jim tollan Avatar answered Oct 04 '22 20:10

jim tollan