Ich habe zwei Formen, Form1 und Form2, beide sind nur MVC-Formulare. Diese Formen mit zwei verschiedenen Ansichtsmodellen wie unten dargestellt:Zugriff auf Modelldaten in Ajax-Antwort
public class Form1ViewModel
{
//some public properties
public string QueryString { get; set; }
}
public class Form2ViewModel
{
//some public properties
public string PreviousQueryString { get; set; }
}
In der Steuerung Beitrag Aktion I wie das hier schreiben:
[HttpPost]
public ActionResult ProcessForm1(Form1ViewModel form1Obj)
{
//some logic goes here
//I'm preparing Querystring from form1 data and appending to Form2 model like
Form2ViewModel form2Obj=new Form2ViewModel();
form2Obj.PreviousQueryString = form1Obj.QueryString;
return View("Form2",form2Obj) ;
}
Und in Form1, ich bin die Einreichung durch JQuery Ajax als
frm.submit(function(ev) {
var formData = frm.serialize();
$.ajax({
type: "POST",
url: 'ControllerName/ProcessForm1',
data: formData,
success: function(response) {
//Here i need to read the PreviousQueryString and need to push to window.history.pushState()
}
error: function() {}
});
});
im Ajax Erfolg, muß ich das PreviousQueryString aus der Antwort lesen.
Ich wusste, wie es Client-Seite (mit reinem JS) tun, aber es ist meine Anforderung.
Wie kann ich es tun?
try '@ Request.QueryString [ "PreviousQueryString"]' –