Why is the parameter not passed from one controller action to another in asp.net mvc?

I have this AddSection method

public ActionResult AddSection(string code, ArrayList added)
    {
        ArrayList list = added;
        if (list == null) list = new ArrayList();
        list.Add(Request["selected_section"]);
        return RedirectToAction("Details", new { code = code, added = list });
    }

Forwarding to details:

public ActionResult Details(string code, ArrayList added)
    {
        if (added == null) added = new ArrayList();
        return View(added);
    }

Now in the Details action (if it is displayed from AddSection), the "added" ArrayList should never be empty, since it is still initialized in AddSection and passed to the details. When I debug the add program, the ArrayList in Details is null, even if the action was shown after AddSection.

Can someone explain why?

+3
source share
1 answer

As LukeP said, it looks like a dup, because, as another question / answer states, only primitive types can be passed, not complex types.

,

public ActionResult AddSection(string code, ArrayList added) {
    ArrayList list = added;
    if (list == null) list = new ArrayList();
    list.Add(Request["selected_section"]);
    TempData["ListOfValues"] = list;
    return RedirectToAction("Details", new { code = code});
}

public ActionResult Details(string code) {
    var added = (ArrayList)TempData["ListOfValues"];
    if (added == null) added = new ArrayList();
    return View(added);
}
+1

All Articles