2012-09-17 76 views
0

我有動作(分析),我想重定向到通過浮動列表的參數等動作,但始終列表爲空:重定向到行動asp.net MVC3

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

那麼,什麼是問題,我該如何修正呢?

+2

我認爲你需要提供有關你正在嘗試做一些更多的信息。 –

+0

當你重定向時調試並檢查sfr是否爲空 – robasta

+0

我嘗試將參數中的float列表傳遞給其他動作,所以我填充它並重定向到新動作,但列表變爲空 – developper

回答

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