5
I know that the TempData
has its "life" maintained until it is used in the View
. However, if I do it on two different controllers, the same one identified from the TempData
, I’m killing and about writing them.
If the user is using 2 browser tabs, it may send the wrong message.
So how can I use the TempData
or other functionality, to send data from a Controller
to the View
, to pass messages, without having the problem with multi tabs. I also did not want to go through URL.
Additional data (Edited)
Code
using (var db = new Conexao())
{
var usuario = db.Usuario.Find(id);
var retorno = EntidadeBaseExt.ValidarRegistro(usuario);
if (retorno != "")
{
TempData["MsgRetornoError"] = retorno;
return RedirectToAction("Index", "Home");
}
return View(usuario);
}
Problem
If the user is using 2 tabs, in the tab 1 it looks for id = 1 and in the tab 2 it looks for id = 3, and both have error return message.
It can happen from the message in tab 2, about writing the message in tab 1, and presenting the wrong information.
This way I would have to pass some way to ensure that tab 1 picks up your message and tab 2 picks up your message.
If I do so:
return RedirectToAction("Index", "Home", new { msg = "Teste " + id.ToString() });
the msg field is in the url and I didn’t want this.
Have you tried Viewbag?
– Ricardo
@Ricardo If you use the command
RedirectToAction
value is null. This is the problem.– Tiedt Tech
Put an example of your code there. Then it’s easier to help.
– Ricardo
@Ricardo improved the question. But you gave me an idea, to do so:
return RedirectToAction("Msg", "Home", new { id = idMensagem });
, where id becomes a Session with the data I need. This way the url is cleared, and decreases the cross-data problem.– Tiedt Tech
I updated the answer, in the code I put you can pass the ID in the url to search and return the data in Session, will work as you want. If you have solved do not fail to mark the answer.
– Ricardo