Dynamic table MVC

Asked

Viewed 281 times

1

I need to return the result of the trial, I put a fixed value just to perform my tests but it will have an input typed, in datepick. However I cannot create the list for the columns.

Follow the code excerpt:

public string dtaTotal(string dtaini, string dtafinal)
    {

       List<string> dtatot = new List<string>();

       var result = "'" + dtaini + "'" + "," + "'" + dtafinal + "'";

       return result;
    }

    private List<Campanha> BuscaCampanhas()
    {
       using (SqlCommand command = new SqlCommand("exec pr_DashBrokerCampanhas '01-09-2018', '10-09-2018'", DBConnection))
       {
           DBConnection.Open();
           using (SqlDataReader reader = command.ExecuteReader())
           {
               List<Campanha> _listCampanhas = new List<Campanha>();

                  while (reader.Read())
                  {
                      _listCampanhas.Add(

                          new Campanha
                          {
                              DescCampanha = reader["DescCampanha"].ToString(),
                              Total = reader["Total"].ToString(),
                              Columns = dtaTotal()
                          }
                      );
                  }

               DBConnection.Close();
               return _listCampanhas;

           }
       }
    }

Class Campaign:

public class Campanha
{
    public string DescCampanha { get; set; }
    public string Total { get; set; }
    public List<string> Columns { get; set; }
}

public class Dashboard
{
    public List<Envio> Envios { get; set; }
    public List<Broker> Brokers { get; set; }
    public List<Campanha> Campanhas { get; set; }
}

Index controller:

        var DashboardContent = new Dashboard();

        DashboardContent.Envios = BuscaTodosEnvios();
        DashboardContent.Brokers = BuscaBrokers();
        DashboardContent.Campanhas = BuscaCampanhas();

        return View(DashboardContent);

1 answer

1

First you need to review your function dtaTotal(string dtaini, string dtafinal), because she expects two parameters that were not passed when she called her in the method BuscaCampanhas(). And, in addition, the method dtaTotal should return a List<string> and you’re not doing it.

As for receiving the value of the Datepicker field in the Controller, there are several ways to do this. The simplest is through the Model Dashboardcontent that you are sending from Controller to the View.

Behold in this article something similar that may guide you in its implementation:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.