I am really new to ASP.NET MVC, but the way I solved it was that I had several buttons in my form and gave each of them a class, and then set the data parameters for them, in this For example, I have two properties from some element Val1 and Val2 for the first button, and two for the second - Val1 and Val3:
<input type="button" value="Button 1" class='button1' data-val1="@item.Val1" data-val2="@item.Val2"/> <input type="button" value="Button 2" class='button2' data-val1="@item.Val1" data-val2="@item.Val3"/>
and then I used some jquery to handle click events and indicated which action to trigger:
<script type="text/javascript"> $(function () { $('.button1').click(function () { var Val1 = $(this).data('val1'); var Val2 = $(this).data('val2'); $.ajax({ type: "POST", data: "val1=" + Val1 + "&val2=" + Val2, url: '@Url.Action("MyAction", "MyController")', dataTyp: "html", success: function (result) { </script>
It seemed to work very well for my needs.
itsmatt
source share