javascript - Submit form from JS code -


i have form:

@model project.models.channelandlocationviewmodel  @{ const string formid = "parentform"; }  @using (html.beginform("editchannel", "channel", formmethod.post, new { id = formid }))     {         html.renderpartial("editchannelform", model);         <br /><br />         <!--<input type="submit" value="save"/>-->      <input type="button" value="save" onclick="editchannel('@model.channelviewmodel.id', @formid)" />      } 

i trying submit form in js code looks this:

function editchannel(channelid, parentform) {   $(parentform).submit();  $.ajax({     url: '/channel/editchannel/',     type: "post",     cache: false,     data: {         id: channelid                 },     success: function (msg) {         alert("msg: " + msg);         if (msg === "changeofsensitivedata") {             showalertonchangeofsensitivedata('sensitivdatamsgdiv');         } else {             alert("else");         }     },     error: function (msg) {         showdialog('errordiv');     } }); } 

but seems form never gets submitted, model not parsed controller. model null once action method called. action looks this:

[httppost]         public actionresult editchannel(int id, channelandlocationviewmodel updatedmodel)         { ...} 

how can submit form js file?

do way:

function editchannel(channelid, parentform) {      $("#formid").submit(function(event) {         event.preventdefault();          $.ajax({             url: '/channel/editchannel/',             type: "post",             cache: false,             data: {                 id: channelid,                 updatedmodel: parentform             },             success: function (msg) {                 alert("msg: " + msg);                 if (msg === "changeofsensitivedata") {                     showalertonchangeofsensitivedata('sensitivdatamsgdiv');                 } else {                     alert("else");                 }             },             error: function (msg) {                 showdialog('errordiv');             }         });     }); } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -