0

我有动作(分析器),我想重定向到传递浮点列表参数的其他动作,但列表总是空的:

  • 在动作分析器中,我填充了浮点列表(sfr),并将它作为参数传递给动作(_two 或 _three 或.... _others),但列表变为空。

    // 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);
             }
        }
    }
    

那么这是怎么回事,我该如何纠正呢?

4

1 回答 1

0

试试这样:

[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);
}
于 2012-09-17T11:05:44.307 回答