jquery - JavaScript - Submit Form - To a specific method on a controller -


i've got mvc 4 app. have following javascript function fires whenever change made element id of 'file'. submit works fine. however, submit specific action method on current controller , not method defined in html.beginform definition. i'm new , not sure how go doing this.

how can change code submit named action method on controller?

$(function () {     $("#file").change(function () {         $("form").submit();     }); }); 

you can set action before submitting form:

$(function () {     $("#file").change(function () {         $("form").attr("action", '@url.action("action", "controller")');         $("form").submit();     }); }); 

update: based on clearer understanding of requirements, if want user stay on same page when posting via change event, can make ajax post, this:

$(function () {     $("#file").change(function () {         var ajaxdata = {             // initialise ajax data pass post target url         };         $.ajax({             url: '@url.action("action", "controller")', // post target url goes here             type: 'post',             data: ajaxdata,             success: function (data, text) {              },             error: function(request, status, error) {              }         });     }); }); 

there further options available ajax calls in jquery docs.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -