1

If I have the following:

        [HttpPost]
        public ActionResult DeclineClaims(String button, String[] Decline)
        {
            if (button == "claim")
            {
                return RedirectToAction("NewExpense", "Claim", new { Create = Decline });
            }

            ....
            ....
        }

and receive it via the RedirectToAction here:

        public ActionResult NewExpense(String[] Create)
        {
            ...
        }

'Create' in the second action is an empty string. This problem does not occur with standard Int and Strings.

How should I handle the String array?

Chris
  • 3,191
  • 4
  • 22
  • 37

2 Answers2

8

You may try this:

[HttpPost]
public ActionResult DeclineClaims(String button, String[] Decline)
{
    if (button == "claim")
    {
        var parameters = new RouteValueDictionary();
        for (int i = 0; i < decline.Length; i++)
        {
            parameters["Create[" + i + "]"] = Decline[i];
        }
        return RedirectToAction("NewExpense", parameters);
    }
    ....
    ....
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

Sender:

        [HttpPost]
        public ActionResult DeclineClaims(String button, String[] Decline)
        {
            if (button == "claim")
            {
                TempData["Create"] = Decline;
                return RedirectToAction("NewExpense", "Claim");
            }

            ....
            ....
        }

Receiver:

        public ActionResult NewExpense()
        {
            String[] data = (String[])TempData["Create"];
        }
Chris
  • 3,191
  • 4
  • 22
  • 37