In .Net 6 and Asp.net Core MVC, if the user wants the list of data in an excel file, I shared the necessary codes for this.
The required codes are in the controller/HomeController. A similar scenario can be followed in other .Net versions as well. There are only package differences.