Hello I am generating an excel file inside my action that I would return to the user. How do I have to declare the action to return a file?
May I call this action with ajax?
thanks!
An ActionResult is a return type of a controller method in MVC. Action methods help us to return models to views, file streams, and also redirect to another controller's Action method.
Action Result is actually a data type. When it is used with action method, it is called return type. As you know, an action is referred to as a method of the controller, the Action Result is the result of action when it executes. In fact, Action Result is a return type.
First to Understand---ActionResult and ViewResult are basically a return type for an method(i.e Action in MVC). Second The Difference is --- ActionResult can return any type of Result Whereas ViewResult can return result type of View Only.
Option 1: Use built in ActionResults, such as FilePathResult, FileStreamResult, FileContentResult
Option 2: Build a custom ActionResult to return your excel file (example: http://www.dotnetcurry.com/ShowArticle.aspx?ID=484&AspxAutoDetectCookieSupport=1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With