重定向到动作asp.net mvc3

时间:2012-09-17 10:53:38

标签: c# asp.net razor

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

  • 在动作分析器中,我填充浮动列表(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);
             }
        }
    }
    

那么问题是什么,我该如何纠正呢?

1 个答案:

答案 0 :(得分: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);
}