如果我有以下内容:
[HttpPost]
public ActionResult DeclineClaims(String button, String[] Decline)
{
if (button == "claim")
{
return RedirectToAction("NewExpense", "Claim", new { Create = Decline });
}
....
....
}
并通过RedirectToAction在此处接收:
public ActionResult NewExpense(String[] Create)
{
...
}
第二个动作中的'Create'是一个空字符串。标准的Int和字符串不会出现此问题。
我应该如何处理String数组?
答案 0 :(得分:8)
你可以试试这个:
[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);
}
....
....
}
答案 1 :(得分:1)
发信人:
[HttpPost]
public ActionResult DeclineClaims(String button, String[] Decline)
{
if (button == "claim")
{
TempData["Create"] = Decline;
return RedirectToAction("NewExpense", "Claim");
}
....
....
}
接收器:
public ActionResult NewExpense()
{
String[] data = (String[])TempData["Create"];
}