Currently, I am working on an MVC project where I need to achieve the following:
The scenario involves sending an ajax request from a JS script and then redirecting to a page along with a model once the request is processed.
I attempted to send a form as the ajax response and submit it using the following method:
sb.Append("<html>");
sb.AppendFormat(@"<body onload='document.forms[""form""].submit()'>");
sb.AppendFormat("<form name='form' action='{0}' method='post'>", "url..");
sb.AppendFormat("<input type='hidden' name='result' value='{0}'>", val1);
.....
In the JavaScript section:
success: function (result) {
var form = $(result);
$(form).submit();
}
However, this approach requires specifying each post parameter individually, whereas my goal is to send the entire model object. How can I achieve that?
Edit The complete process is outlined below:
1. Development is being carried out in an MVC application.
2. A submit button in the view triggers redirection to the JavaScript code.
3. The JavaScript code initiates an Ajax request to a specific MVC page named 'Transaction'.
4. Once certain actions are performed in the C# code, I need to redirect the user to a page called EOF with a large number of post parameters, which is why I wish to pass it as a ViewModel.