Im trying to pass data from one controller to another. i have a Pet that i need to parse to a Message controller. Basicly i have a user who creates a pet, then other users can send messages to other pet owners through the WebAPP. on Pets/Details i have a button calling the action SendMessage(shown below)
Currently i get a unhandled exception: InvalidOperationException: Session has not been configured for this application or request. Microsoft.AspNet.Http.Internal.DefaultHttpContext.get_Session()
PetsController.CS:
public IActionResult SendMessage(int id)
{
Pet PetData = _context.Pet.Single(m => m.ID == id);
TempData["PetData"] = PetData;
return RedirectToAction("Create", "Message");
}
Then i need to move that pet object to my messagesController:
// POST: Messages/Create
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(Message message)
{
if (ModelState.IsValid)
{
_context.Message.Add(message);
Pet Data = TempData["PetData"] as Pet;
message.SentTo = Data.CreatedBy;
message.Subject = Data.Name;
_context.SaveChanges();
return RedirectToAction("Index");
}
return View(message);
}
I hope that someone can help me with the Issue. Just to mention it, im new to MVC.