且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法将用户重定向到支付网关的付款页面?

更新时间:2023-11-30 11:46:10

MVC不使用控制树;你只需要将原始HTML返回给用户:

 [HttpPost] 
public ActionResult演示(字符串 amt,字符串名称,字符串 emaill, string phno, string prod)
{
...
string strForm = PreparePOSTForm(action1,data);
return 内容(strForm,System.Net.Mime.MediaTypeNames.Text.Html);
}


dear sir/madam

c# - PayUMoney Integration in MVC and calling using ajax - Stack Overflow[^]

i am facing the same problem mentioned in the above link.
so respected members provider your advice and help.
thanks for your help in advance

What I have tried:

the gateway provide have provide the code in asp.net and i wanted to use it in mvc
when i use this code in mvc
Page.Controls.Add(new LiteralControl(strForm));//this line give me error.

public string Generatehash512(string text)
{

byte[] message = Encoding.UTF8.GetBytes(text);

UnicodeEncoding UE = new UnicodeEncoding();
byte[] hashValue;
SHA512Managed hashString = new SHA512Managed();
string hex = "";
hashValue = hashString.ComputeHash(message);
foreach (byte x in hashValue)
{
hex += String.Format("{0:x2}", x);
}
return hex;

}

public string Generatetxnid()
{
Random rnd = new Random();
string strHash = Generatehash512(rnd.ToString() + DateTime.Now);
return strHash.ToString().Substring(0, 20);
}

[HttpPost]
public void demo(string amt, string name, string emaill, string phno, string prod)
{
string firstName = name;
string amount = amt;
string productInfo = prod;
string email = emaill;
string phone = phno;

string key = "";
string salt = "";
string txnid = Generatetxnid();
string hashString = key + "|" + txnid + "|" + amount + "|" + productInfo + "|" + firstName + "|" + email + "|||||||||||" + salt;
string hash = Generatehash512(hashString).ToLower();
System.Collections.Hashtable data = new System.Collections.Hashtable(); // adding values in gash table for data post
data.Add("hash", hash);
data.Add("txnid", txnid);
data.Add("key", key);
data.Add("amount", amount);
data.Add("firstname", name);
data.Add("email", email);
data.Add("phone", phone);
data.Add("productinfo", productInfo);
data.Add("surl", "http://localhost:61818/Default/Sucess");
data.Add("furl", "http://localhost:61818/Default/Failure");
data.Add("service_provider", "payu_paisa");
action1 = "https://sandboxsecure.payu.in/_payment";
string strForm = PreparePOSTForm(action1, data);
// Page.Controls.Add(new LiteralControl(strForm));//Giving Error
}
private string PreparePOSTForm(string url, System.Collections.Hashtable data) // post form
{
// Set a name for the form
string formID = "PostForm";
// Build the form using the specified data to be posted.
StringBuilder strForm = new StringBuilder();
strForm.Append("");

foreach (System.Collections.DictionaryEntry key in data)
{

strForm.Append("");
}
strForm.Append("");
// Build the JavaScript which will do the Posting operation.
StringBuilder strScript = new StringBuilder();
strScript.Append("");
strScript.Append("var v" + formID + " = document." +
formID + ";");
strScript.Append("v" + formID + ".submit();");
strScript.Append("");
// Return the form and the script concatenated.
// (The order is important, Form then JavaScript)
return strForm.ToString() + strScript.ToString();
}
}

MVC doesn't use a control tree; you just need to return the raw HTML to the user:
[HttpPost]
public ActionResult demo(string amt, string name, string emaill, string phno, string prod)
{
    ...
    string strForm = PreparePOSTForm(action1, data);
    return Content(strForm, System.Net.Mime.MediaTypeNames.Text.Html);
}