0
I’m starting my career in development, and in the company project here, I found a ViewData
being used, and for my researches I can not update it in a ActionResult
in the controller. I ended up testing with a ViewBag
also, where I was also unhappy. Remembering that the value of these two will be assigned in the page rendering, correct? (Please correct me)
How could I do to recover this values, via ajax
, until another question, because my functions . js are in another file, not located within the Index.cshtml
Edit 1: In my current scenario, the following is happening:
public IActionResult Index()
{
// Crio minha ViewData
ViewData["NomeDaViewData"] = null;
UpdateViewData(); // aqui onde vou atualizá-la
return View();
}
private void UpdateViewData()
{
var dado = _myReposiory.BuscaValor();
ViewData["NomeDaViewData"] = dado;
}
Right after in my Index I play the value of Viewdata in a Hidden input, where I can work in my file . js quietly. But I see I can better this way, I just don’t know how.
when you say "via ajax," you mean
javascript
needs a value that has been passed downViewData
orViewBag
that’s it?– Ricardo Pontual
You want to pass the value of the ajax in the View to the Controller?
– Robson Oliveira
That’s right @Ricardopunctual.
– Vinícius Avansini
I would like to pass a value that is in my Controller to my View @Robsonoliveira
– Vinícius Avansini