There are many approaches for calling controller, action from JQuery, but this one is pretty simple.
So jumping right to the point.
- function PageRedirect(event) {
- var act = event.data.act
- var cnt = event.data.cnt;
- var formName = $('form').attr('id');
- var form = $('#' + formName);
- form.attr("action", '/' + cnt + '/' + act);
- form.submit();
- }
This javscript method can be put in master page.
It can be called from cshtml with the following code.
- <script type="text/javascript">
- $('#btnSearch').click({ act: "Search", cnt: "Students" }, PageRedirect);
- </script>
For those wondering, how is this possible, check this
link
Pretty simple.