javascript - How to access Model Data in Ajax response -


i have 2 forms, consider form1 , form2, both mvc forms only. these forms using 2 different view models shown below :

public class form1viewmodel {      //some public properties       public string querystring { get; set; } }   public class form2viewmodel {      //some public properties       public string previousquerystring { get; set; } } 

in controller post action i'm writing :

[httppost] public actionresult processform1(form1viewmodel form1obj) {      //some logic goes here       //i'm preparing querystring form1 data , appending form2 model       form2viewmodel form2obj=new form2viewmodel();      form2obj.previousquerystring = form1obj.querystring;       return view("form2",form2obj) ; } 

and in form1, i'm submitting through jquery ajax as

 frm.submit(function(ev) {    var formdata = frm.serialize();    $.ajax({      type: "post",      url: 'controllername/processform1',      data: formdata,      success: function(response) {        //here need read previousquerystring , need push window.history.pushstate()      }      error: function() {}    });  }); 

in ajax success, need read previousquerystring response.

i knew how client side(using pure js) it's requirement.

how can it?

try

[httppost] public string processform1(form1viewmodel form1obj) {      javascriptserializer js = new javascriptserializer();      form2viewmodel form2obj=new form2viewmodel();      form2obj.previousquerystring = form1obj.querystring;       return js.serialize(form2obj);  }  success: function(response) {           var objresponse = $.parsejson(response);         if (objresponse.previousquerystring != "") {            alert(objresponse.previousquerystring);         }     } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -