JQuery Method for Calling Controller, Action in MVC

There are many approaches for calling controller, action from JQuery, but this one is pretty simple.
 
So jumping right to the point. 
  1. function PageRedirect(event) {  
  2.     var act = event.data.act  
  3.     var cnt = event.data.cnt;  
  4.     var formName = $('form').attr('id');  
  5.     var form = $('#' + formName);  
  6.     form.attr("action"'/' + cnt + '/' + act);  
  7.     form.submit();  

This javscript method can be put in master page.
 
It can be called from cshtml with the following code. 
  1. <script type="text/javascript">  
  2.     $('#btnSearch').click({ act: "Search", cnt: "Students" }, PageRedirect);  
  3. </script> 
For those wondering, how is this possible, check this link  
 
Pretty simple.
Ebook Download
View all
Learn
View all