2
I need to send a parameter from one action to another action in the same controller, but the parameter is "reset". How can I do this? Down with the code I’m making:
[Authorize]
public class ItemMaloteController : Controller
{
public IActionResult Index(Guid id)
{
ViewBag.ItemsMaloteList = _itemMaloteRepository.GetAll()
.Where(x => x.MaloteId.Equals(id)).ToList();
ViewBag.Malote = _maloteRepository.GetAll()
.Where(x => x.Id.Equals(id)).ToList();
ViewBag.Curso = _cursoRepository.GetAll().ToList();
ViewBag.Documentos = _documentosRepository.GetAll();
ViewBag.MaloteId = id;
return View();
}
public IActionResult Create(ItemMalote itemMalote)
{
if (!ModelState.IsValid)
return NotFound();
itemMalote.Id = Guid.NewGuid();
_itemMaloteRepository.Register(itemMalote);
_itemMaloteRepository.SaveChanges();
var maloteId = _itemMaloteRepository.GetMalote(itemMalote.MaloteId).Select(x => x.MaloteId).ToList();
//Aqui eu chamo minha action "Index" e passo o parametro
return RedirectToAction("Index", maloteId);
}
}
It happens that when it arrives again in the action "Index" the parameter arrives "zeroed". I tried to pass via Tempdata, but the same happens.
Only the Return was missing :)
– George Wurthmann
True, I had forgotten... I have already edited the answer. Thank you very much!
– Pedro Paulo