Call a method in MVC .Net Command

Viewed 50

I'm new to MVC. I have a button to do an export to excel. On the Command class I have FilterData() and ExportData() method. This data have been filtered from a FilterData() method with a select.

public DataTable FilterData()
{
   //My code to filter data
   sql= "select * from table where date = today()"
}

public IEnumerable<DB_Data> ExportData() //this is for the export button
{
   //My code to export data
}

My question is, in my Command class and as the result of the two methods is the same, how can I call the FilterData() method on the ExportData() method so I can export only the rows I have filtered?

1 Answers

As @Anand Sowmithiran said those are two different concepts.

For your requirement you can do like below:

  • In controller, get the data from database with DbContext.
  • Then export data to excel from the above filtered data list.
  • You can achieve this in Code First approach.

Thanks @Mukesh Kumar for this nice article, Export Data In Excel File With ASP.NET MVC.

Related