Hello, I have a DropDownList, coming from a ViewBag, and I need to write this value to some kind of "global variable". I researched and saw that the best ways to do this are by writing to a ViewBag or a ViewModel.
Scenario: When the user logs on to the system, he will have to choose which contract he wants to access (in a DropDownList). I need this value to be saved, and I can use it in a query soon after, to show data only from this contract. The login is working properly, and I was able to list the contracts in a DropDownList, coming from a viewbag. I just need to get this selected value and use it in another query.
DropDownList code:
ViewBag.Contrato = usuarioRepository.Lista.Where(u => u.sLogin == autenticacaoProvider.UsuarioAutenticado.Login).Select(u => u.SqContrato);
View calling DropDownList:
@Html.DropDownList("Contrato", new SelectList(ViewBag.Contrato, "Contrato"))
I'm having difficulty creating the method in the controller that will save this flaw, so I can use it again.
If you need more code, just comment, that post here.