Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have jquery buttons in my program.But i dont know how to call action method while the button clicked.Please help me out. Check below for coding

What I have tried:

Jquery
this.buttons = {
      next: $('<a>' + options.labelNext + '</a>').attr("href", "#").addClass("buttonNext"),
      previous: $('<a>' + options.labelPrevious + '</a>').attr("href", "#").addClass("buttonPrevious"),
      finish: $('<a>' + options.labelFinish + '</a>').attr("href","#").addClass("buttonFinish")
  };
Posted
Updated 2-Oct-17 20:41pm
Comments
F-ES Sitecore 3-Oct-17 4:50am    
Google "call mvc action jquery" and you'll find lots of code for this. Asking people to write your code then simply saying "doesn't work" is wasting our time as much as yours.
GrpSMK 3-Oct-17 5:07am    
already i tried after that only i posted man

$(document).ready(function() {
    $(".buttonNext").click(function() {
         document.location = '@Url.Action("YourActionName","ControllerName")';
    });
    $(".buttonPrevious").click(function() {
         document.location = '@Url.Action("YourActionName","ControllerName")';
    });
    $(".buttonFinish").click(function() {
         document.location = '@Url.Action("YourActionName","ControllerName")';
    });
});
 
Share this answer
 
v2
Comments
GrpSMK 3-Oct-17 2:31am    
i dont have any button in html format this jquery only displaying as buttons
Iman Memarpour 3-Oct-17 2:42am    
Just add this to your JQuery code. Should do the trick.
GrpSMK 3-Oct-17 3:39am    
not working.
GrpSMK 3-Oct-17 3:40am    
No.its not working given below is predefined code for finish button
//$($this.buttons.finish).click(function () {
// if (!$(this).hasClass('buttonDisabled')) {
// if ($.isFunction($this.options.onFinish)) {
// var context = { fromStep: $this.curStepIdx + 1 };
// if (!$this.options.onFinish.call(this, $($this.steps), context)) {
// return false;
// }
// } else {
// var frm = $this.target.parents('form');
// if (frm && frm.length) {
// frm.submit();
// }
// }
// }
// return false;
//}); this is the prefined code for finish button click
try like this

function callAction(btn) {
         var button = btn.innerText; //Next,Previous,Finish
         if (button == 'Next') {
             // your code to call the action...
         }
     }

     this.buttons = {
         next: $('<a onclick="callAction(this)" >' + options.labelNext + '</a>').attr("href", "#").addClass("buttonNext"),
         previous: $('<a onclick="callAction(this)" >' + options.labelPrevious + '</a>').attr("href", "#").addClass("buttonPrevious"),
         finish: $('<a onclick="callAction(this)" >' + options.labelFinish + '</a>').attr("href", "#").addClass("buttonFinish")
     };
 
Share this answer
 
Comments
GrpSMK 3-Oct-17 3:10am    
No.its not working given below is predefined code for finish button
//$($this.buttons.finish).click(function () {
// if (!$(this).hasClass('buttonDisabled')) {
// if ($.isFunction($this.options.onFinish)) {
// var context = { fromStep: $this.curStepIdx + 1 };
// if (!$this.options.onFinish.call(this, $($this.steps), context)) {
// return false;
// }
// } else {
// var frm = $this.target.parents('form');
// if (frm && frm.length) {
// frm.submit();
// }
// }
// }
// return false;
//});
Karthik_Mahalingam 3-Oct-17 3:50am    
can you host your code in jsfiddle and share the link
GrpSMK 3-Oct-17 4:01am    
https://jsfiddle.net/mogan777/7vvdyvd4/
Karthik_Mahalingam 3-Oct-17 5:47am    
No UI, what i will check in that.
GrpSMK 3-Oct-17 6:52am    
@Html.RadioButtonFor(model => Model.SelectedAnswer, "1", new { @class = "col-lg-4 col-md-4 col-sm-4" })
@Html.RadioButtonFor(model => Model.SelectedAnswer, "2", new { @class = "col-lg-4 col-md-4 col-sm-4" })
@Html.RadioButtonFor(model => Model.SelectedAnswer, "3", new { @class = "col-lg-4 col-md-4 col-sm-4" })
@*

*@

Like this three sections

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900