I am trying to integrate a payment gateway using mvc4 in a razor. The fact that I need to call a page with a pre-filled message form.
Using the following method, I form the form of the post method:
private static string PreparePOSTForm(string url, System.Collections.Hashtable data)
{
string formID = "PostForm";
StringBuilder strForm = new StringBuilder();
strForm.Append("<form id=\"" + formID + "\" name=\"" +
formID + "\" action=\"" + url +
"\" method=\"POST\">");
foreach (System.Collections.DictionaryEntry key in data)
{
strForm.Append("<input type=\"hidden\" name=\"" + key.Key +
"\" value=\"" + key.Value + "\">");
}
strForm.Append("</form>");
StringBuilder strScript = new StringBuilder();
strScript.Append("<script language='javascript'>");
strScript.Append("var v" + formID + " = document." +
formID + ";");
strScript.Append("v" + formID + ".submit();");
strScript.Append("</script>");
return strForm.ToString() + strScript.ToString();
}
And on my controller page, I call PreparePostFormwith the required parameter, and I get the POST request format.
[HttpPost]
public ActionResult OrderSummary()
{
string request=PreparePOSTForm("payment URL","hashdata required for payment")
return Redirect(request);
}
But when redirecting, I get below the error.
Invalid request - invalid URL
HTTP Error 400. Invalid request url.
I am missing something here to work with a POST request. Can someone help me.
Thanks in advance.
source
share