When redirect you can only pass query string values. Not entire complex objects:
return RedirectToAction("Success", new {
prop1 = model.Prop1,
prop2 = model.Prop2,
...
});
This works only with scalar values. So you need to ensure that you include every property that you need in the query string, otherwise it will be lost in the redirect.
Another possibility is to persist your model somewhere on the server (like a database or something) and when redirecting only pass the id which will allow to retrieve the model back:
int id = StoreModel(model);
return RedirectToAction("Success", new { id = id });
and inside the Success action retrieve the model back:
public ActionResult Success(int id)
{
var model = GetModel(id);
...
}
Yet another possibility is to use TempData
although personally I don't recommend it:
TempData["model"] = model;
return RedirectToAction("Success");
and inside the Success
action fetch it from TempData
:
var model = TempData["model"] as PersonalDataViewModel;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…