0
Good morning I have this Hidden that gets the value correctly:
<input type="hidden" id="idHorario"/>
But I need to get the Hidden in the code, how can I proceed?
HorariosItens = await _context.HorariosItens
.Include(a => a.Horarios)
.Where(a => a.HorarioId == ["hidden aqui"] )
.ToListAsync();
I am unable to pass the value of Hidden to the condition.
Edit: I have this function where you send the Horarioid to save to the Horarioitem/Create page
function ListarItens(idHorario) {
var url = "/HorarioItem/Create";
$.ajax({
url: url
, type: "GET"
, data: { id: idHorario }
, datatype: "html"
, success: function (data) {
console.log(idHorario);
var divItens = $("#divItens");
divItens.empty();
divItens.show();
divItens.html(data);
$("#idItem").val("0");
$("#idHorario").val(idHorario);
}
});
}
And this one to save:
public async Task<ActionResult> SalvarItens(Horarios h, string HoraInicio, string HoraFim, bool Seg, bool Ter, bool Qua, bool Qui, bool Sex, bool Sab, bool Dom, bool Fer, int Tipolimite, int Limiteacessos, int HorarioId)
{
h.Id = HorarioId;
var item = new HorariosItens()
{
HoraFim = HoraFim,
HoraInicio = HoraInicio,
Seg = Seg,
Ter = Ter,
Qua = Qua,
Qui = Qui,
Sex = Sex,
Sab = Sab,
Dom = Dom,
Fer = Fer,
Tipolimite = Tipolimite,
Limiteacessos = Limiteacessos,
HorarioId = HorarioId,
};
//try
//{
ViewData["hor"] = HorarioId;
_context.HorariosItens.Add(item);
_context.SaveChanges();
//HorariosItens = await _context.HorariosItens
// .Include(a => a.Horarios).Where(a => a.HorarioId == HorarioId).ToListAsync();
//}
//catch (Exception ex)
//{
// throw ex;
//}
return new JsonResult(new { Resultado = item.Id });
}
And then on this, where I should list the items schedules, but I’m not able to work passing the id:
public IList<HorariosItens> HorariosItens { get; set; }
public async Task<IActionResult> OnGetAsync()
{
try
{
HorariosItens = await _context.HorariosItens
.Include(a => a.Horarios).Where(a => a.HorarioId == int.Parse(ViewData["hor"].ToString())).ToListAsync();
}
catch
{
HorariosItens = await _context.HorariosItens
.Include(a => a.Horarios).Where(a => a.HorarioId == 0).ToListAsync();
}
//ViewData["HorarioId"] = new SelectList(_context.Horarios, "Id", "Nome");
return Page();
}
I even put a Try catch, but it smp falls in the catch.
<input type="hidden" id="idHorario"/>
it should be like this<input type="hidden" id="idHorario" name="idHorario"/>
because what counts for programming is thename
ofinput
!!!– novic
I still can’t do it.
– Mariana
What did you put in the ??? That’s more or less the way:
GetAprovacaoEmendaById(int idHorario)
!!! to rescue!– novic
@Virgilionovic edited the question so you can understand. thanks.
– Mariana
Here
, data: { id: idHorario }
trial,data: { id: document.getElementById('idHorario').value }
– Marconi
But then passes the normal value, I need to pick to bring the items, the idHorario there, It is filled.
– Mariana