I honestly don’t know if this post is great or godawful.
What I wanted to do was to have a post method redirect to another method. When you redirect, by definition, you will call the HttpGet version of a method.
What I wanted to do was:
HttpPost to FOO(Complex Object/Hashtable/FormValueCollection), and then at the end of the method, do a return RedirectToAction(“BAR”,object)
HttpGet to BAR(Complex Object/Hashtable/FormValueCollection)
kind of like this: http://stack247.wordpress.com/2011/03/20/get-forms-post-values-in-asp-net-mvc-with-formcollection/
I think it’s not possible.
But what I did get to work was:
HttpPost to FOO(Complex Object/Hashtable/FormValueCollection), and then at the end of the method, do a return RedirectToAction(“BAR”,RouteValueDictionary)
HttpGet to BAR(string param1, string param2, string ccname, string ccamt, string ccstreet, etc spelling out all parameter names in the controller definition)
and I didn’t touch the Routes.
As long as I passed a RouteValueDictionary from the first controller, and specified the names of the parameters I wanted to receive in
the second controller, my method worked.
The methods:
[HttpPost]
public ActionResult VSHcard(Models.VSHcardForm v)
{
try
{
Models.UTKAppRepository objApp = new Models.UTKAppRepository();
payment objP = null;
int iRet = objApp.VSHcardObjectToTouchnetPaymentObjectAndSave(v , ref objP, ref strError);
ViewBag.BillName = “test billname”;
ViewBag.AMT = “1234.56”;
if (iRet < 0)
{
ViewBag.lblError = strError;
}
// return View();
// try redirecting to the get version of the touchnet.create method
RouteValueDictionary dict = new RouteValueDictionary();
System.Collections.Hashtable ht = objP.get_Hashtable();
foreach (string skey in ht.Keys)
{
dict.Add(skey, ht[skey]);
}
//dict.Add(“BILL_NAME”, objP.BILL_NAME);
//dict.Add(“AMT”, objP.AMT);
//dict.Add(“ID”, 2001);
return RedirectToAction(“../Payment/Create”, dict); // HttpGet from Redirect
// we can’t send a hashtable over! return RedirectToAction(“../Payment/Create”, ht); // HttpGet from Redirect
//return RedirectToAction(“../Payment/Create”, new RouteValueDictionary(new { BILL_NAME = objP.BILL_NAME, AMT = objP.AMT })); // HttpGet from Redirect
// return RedirectToAction(“Create”, “Payment”, new RouteValueDictionary(new { BILL_NAME = objP.BILL_NAME, AMT = objP.AMT })); // HttpGet from Redirect
}
catch
{
return View();
}
}
[HttpGet]
public ActionResult Create(int? id,
string BILL_NAME,
int? UPAY_SITE_ID,
string BILL_EMAIL_ADDRESS,
string BILL_STREET1,
string BILL_STREET2,
string BILL_CITY,
string BILL_STATE,
string BILL_POSTAL_CODE,
string BILL_COUNTRY,
string EXT_TRANS_ID,
string EXT_TRANS_ID_LABEL,
decimal? AMT,
string SSV,
string SSV_PROMPT,
string VALIDATION_KEY,
string SUCCESS_LINK,
string SUCCESS_LINK_TEXT,
string ERROR_LINK,
string ERROR_LINK_TEXT,
string CANCEL_LINK,
string CANCEL_LINK_TEXT)
{
ViewBag.Message = “this is the get version of the Create method ” + id.ToString() + BILL_NAME;
// pull data out of the formCollection and put it into ViewData so the View can use it
// ref: http://stack247.wordpress.com/2011/03/20/get-forms-post-values-in-asp-net-mvc-with-formcollection/
//foreach (string _formData in formCollection.Keys)
//{
// ViewBag[_formData] = formCollection[_formData];
//}
ViewBag.BILL_NAME = BILL_NAME;
ViewBag.UPAY_SITE_ID = UPAY_SITE_ID.ToString();
ViewBag.BILL_EMAIL_ADDRESS = BILL_EMAIL_ADDRESS;
ViewBag.BILL_STREET1 = BILL_STREET1;
ViewBag.BILL_STREET2 = BILL_STREET2;
ViewBag.BILL_CITY = BILL_CITY;
ViewBag.BILL_STATE = BILL_STATE;
ViewBag.BILL_POSTAL_CODE = BILL_POSTAL_CODE;
ViewBag.BILL_COUNTRY = BILL_COUNTRY;
ViewBag.EXT_TRANS_ID = EXT_TRANS_ID;
ViewBag.EXT_TRANS_ID_LABEL = EXT_TRANS_ID_LABEL;
ViewBag.AMT = AMT.ToString();
ViewBag.SSV = SSV;
ViewBag.SSV_PROMPT = SSV_PROMPT;
ViewBag.VALIDATION_KEY = VALIDATION_KEY;
ViewBag.SUCCESS_LINK = SUCCESS_LINK;
ViewBag.SUCCESS_LINK_TEXT = SUCCESS_LINK_TEXT;
ViewBag.ERROR_LINK = ERROR_LINK;
ViewBag.ERROR_LINK_TEXT = ERROR_LINK_TEXT;
ViewBag.CANCEL_LINK = CANCEL_LINK;
ViewBag.CANCEL_LINK_TEXT = CANCEL_LINK_TEXT;
return View();
}