I´m developing a school project(with c#, asp.net) that recieves data input from a view with selects and others inputs(dates and text), from this view:
That have this code, the input of date(2 of them)
<input id="Inicial" type="date" name="Inicial" />
Thats the first select
<select asp-for="AcessoVisita" >
<option value="null">Escolha uma opção para o filtro</option>
<option value="acessos">Número de Acessos</option>
<option value="visitas">Número de Visitas</option>
</select>
The other select is
<select asp-for="tempo" >
<option value="null"> Escolha uma opção para o filtro </option>
<option value="day"> Dia </option>
<option value="month"> Mês </option>
<option value="year"> Ano </option>
</select>
And the last select is that, where i use a foreach cicle to create options to all "Aps" i have.
<select asp-for="ap" >
<option value="null"> Escolha um Ap ou todos</option>
<option value="todos"> Todos os AP's' </option>
@foreach(var i in Model.Aps)
{
<option [email protected]_id> @i.ap_name </option>
}
</select>
Thats the model and the variable he have
public class dadosPassar
{
public List<L_AccessPoint> Aps { get; set; }
public DateTime Inicial { get; set; }
public DateTime Final { get; set; }
public string? AcessoVisita { get; set; }
public string? ap { get; set; }
public string? tempo { get; set; }
}
And thats L_AcessPoint structure
public class L_AccessPoint
{
public string? ap_name { get; set; }
public short? zone_id { get; set; }
public decimal? latitude { get; set; }
public decimal? longitude { get; set; }
public string? ap_eth_mac { get; set; }
public DateTime ts { get; set; }
public short? ap_id { get; set; }
public Byte? type { get; set; }
public bool? Active { get; set; }
}
I has testing what happen when i let some of the input values in the default and the code throws the following exception: Exception throwed
That's the return from the database Database return I can verify if all of other variables dont have the default value but in the last select that throws the exception and i dont know why.
So what I'm doing wrong? And how can i make that rigth?
CodePudding user response:
Thanks a lot for the help.
The problem I had was because I forgot to pass the model to the view. I was rendering like that the view.
if(ds.Inicial >=ds.Final || ds.AcessoVisita == "null" || ds.tempo == "null" || ds.ap== "null")
{
return View("Filtros");
}
So i solved my problem passing the dp with the view
if(ds.Inicial >=ds.Final || ds.AcessoVisita == "null" || ds.tempo == "null" || ds.ap== "null")
{
dadosPassar dp = new dadosPassar();
var objAPs = _db.L_AccessPoint.ToList();
dp.Aps = objAPs;
return View("Filtros", dp);
}