1
votes

How to I Redirect to a Page and Passing its model? Just like what we have in MVC return View(model: MyModel);

What i have tried: return RedirectToPage("/Notify", new { Model = notifierVM });

enter image description here

Note: the Page I want to return has no PageModel behind

1
Check this out - it's about using DI service to set data on one page and load on other stackoverflow.com/questions/46772632/… - Dmitry Pavlov

1 Answers

1
votes

MVC has built in dictionary object TempData. You can serialize your model, put JSON string into TempData and then on the redirected action you can get and deserialize JSON string into object.

public ActionResult Create(Booking item)
{
    TempData["data"] = JsonConvert.SerializeObject(MyModel);
    return RedirectToAction("Details", new { id = 1 });
}

On other action

public ActionResult Details(int id)
{
    object o;
    TempData.TryGetValue("data", out o);
    var MyModel = JsonConvert.DeserializeObject<T>((string)o);
    ...
    ...
}