Good morning I have this hidden one that receives 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'm not able to pass the value of hidden to the condition.
Edit: I have this function where I send the SaveItem to save in the ScheduleItem / 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 in this, where should I list the schedules items, however I can not work by 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 put up a try catch, but it smp drops into catch.