Home > Software design >  When i pass low data quantity the values go to the action fine, but when i pass high quantity that a
When i pass low data quantity the values go to the action fine, but when i pass high quantity that a

Time:05-05

I'm developing a school project using asp.net core with c#, my problem is when i click in a button i need to pass the data that i have inside my view to a new action. I'm using that form to send the data to my method

<form asp-action="PessoasCOunt" method="post">
        
   
    <input asp-for="Inicial" hidden/>
    <input asp-for="Final" hidden/>
    <input asp-for="AcessoVisita" hidden />
    <input asp-for="tempo" hidden/>
    <input asp-for="ApZona" hidden/>
      @foreach(var i in Model.ap)
        {
            <input asp-for="ap" hidden/>
        }

    
        @for(int i=0; i<Model.dados2.Count();i  )
        { 
            <input asp-for="dados2[i].ap_id" hidden/>
            <input asp-for="dados2[i].ap_name" hidden/>
            <input asp-for="dados2[i].numeroAcessos" hidden/>
            <input asp-for="dados2[i].year" hidden/>
            <input asp-for="dados2[i].MES" hidden/>
        <input asp-for="dados2[i].DIA" hidden/>
        
    }
    <div style="margin-bottom:2%;margin-top:2%;">
        <input type="submit" value="Consultar"  />
    </div>
               
</form>

Thats the structure that i'm passing to the method.

public class dadosPassar
    {
        public List<Stored1>? dados2 { get; set; }
        public List<L_AccessPoint>? Aps { get; set; } = new List<L_AccessPoint>();
        public List<L_Zone>? Zones { get; set; } = new List<L_Zone>();
        public List<int>? ap { get; set; } 
        public DateTime Inicial { get; set; }
        public DateTime Final { get; set; }
        public string? AcessoVisita { get; set; }
        public string? tempo { get; set; }
        public string? ApZona { get; set; }
    }

And that method

public FileResult PessoasCOunt(dadosPassar dp)
        {
            //Retornar dados dos Aps escolhidos
            var objap = new List<L_AccessPoint>();
            if (dp.ApZona == "zonas")
            {
                for (int i = 0; i < dp.ap.Count(); i  )
                {
                    var objzones = _db.L_AccessPoint.Where(s => s.zone_id == dp.ap[i]).ToList();
                    for (int j = 0; j < objzones.Count; j  )
                    {
                        objap.Add(objzones[j]);
                    }
                }
                dp.Aps = objap;
            }
            else
            {
                //ds.Apzona é aps
                for (int i = 0; i < dp.ap.Count(); i  )
                {
                    var objzones = _db.L_AccessPoint.Where(s => s.ap_id == dp.ap[i]).ToList();
                    for (int j = 0; j < objzones.Count; j  )
                    {
                        objap.Add(objzones[j]);
                    }
                }
                dp.Aps = objap;
            }
            //criar stringBuilder para poder retornar o ficheiro
            StringBuilder sb = new StringBuilder();
            string filename = dp.AcessoVisita   dp.Inicial.ToString()   "_"   dp.Final.ToString()   ".csv";
            return File(System.Text.Encoding.Unicode.GetBytes(sb.ToString()), "text/csv", filename);
        }

When i select only 6 elements,the data arrives correctly to the method

1

2

But when i pass much data, the values arrives null

4

5

Thats the data that i'm passing.

6

Anyone know why is that happening?

CodePudding user response:

So I could solve my problem by using a complete diferent way. To do that i used Session Variables to store the data the i retrieve from the database and i can use that in every action i want.

  • Related