简体   繁体   中英

Redirection to action asp.net mvc3

I have the action (analyser) and I want to redirect to other actions passing the argument of a list of float, but always the list is empty:

  • In the action Analyser, I fill the list(sfr) of floats and I pass it like an argument to the actions(_two or _three or.... _others) but the list become empty.

     // GET: /Historique/ [HttpGet] public ActionResult Index() { return View(); } [HttpGet] public ActionResult _two(IList<float> sf) { return View(sf); } [HttpGet] public ActionResult _three(IList<float> sf) { return View(sf); } [HttpGet] public ActionResult _four(IList<float> sf) { return View(sf); } [HttpGet] public ActionResult _five(IList<float> sf) { return View(sf); } [HttpGet] public ActionResult _six(IList<float> sf) { return View(sf); } [HttpGet] public ActionResult _others(IList<float> sf) { return View(sf); } [HttpPost] public ActionResult Analyser(FormCollection collection) { IList<float> sfr = new List<float>(); for (int i = 0; i < Global.seg.Count; i++) { if (collection.AllKeys.Contains(i.ToString())) { foreach (Point e in Global.seg[i]._pointsListe) { sfr.Add(e._latitude); sfr.Add(e._longitude); } } } if (sfr.Count == 4) return RedirectToAction("_two", new { sf = sfr }); if (sfr.Count == 6) return RedirectToAction("_two", new { sf = sfr }); if (sfr.Count == 8) return RedirectToAction("_four", new { sf = sfr }); if (sfr.Count == 10) return RedirectToAction("_five", new { sf = sfr }); if (sfr.Count == 12) return RedirectToAction("_six", new { sf = sfr }); else return RedirectToAction("_others",sfr); } } } 

So what is the matter and how can I correct it?

Try like this:

[HttpPost]
public ActionResult Analyser(FormCollection collection)
{
    IList<float> sfr = new List<float>();
    for (int i = 0; i < Global.seg.Count; i++)
    {
        if (collection.AllKeys.Contains(i.ToString())) 
        {
            foreach (Point e in Global.seg[i]._pointsListe)
            {
                sfr.Add(e._latitude);
                sfr.Add(e._longitude);
            }
        }
    }

    var rvd = new RouteValueDictionary();
    for (int i = 0; i < sfr.Count; i++)
    {
        rvd[string.Format("sf[{0}]", i)] = sfr[i];
    }

    if (sfr.Count == 4) return RedirectToAction("_two", rvd);
    if (sfr.Count == 6) return RedirectToAction("_two", rvd);
    if (sfr.Count == 8) return RedirectToAction("_four", rvd);
    if (sfr.Count == 10) return RedirectToAction("_five", rvd);
    if (sfr.Count == 12) return RedirectToAction("_six", rvd);
    else return RedirectToAction("_others", rvd);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM