Priya
Priya

Reputation: 591

How to download a file from the view in mvc?

My requirement is to download a table that is present in the view in mvc

If I click a button, the table present in the view should be downloaded as excel file. In angularjs, I used option as ng-csv for this. But I don't know whether similar kind of option is present in mvc?

Could anyone help me with this ?

Upvotes: 1

Views: 254

Answers (1)

bedane
bedane

Reputation: 1127

I'm not sure of what you mean by "a file that is present in the view".

If the user's file is generated server-side upon request, your button should link to an ActionMethod which returns a

FileContentResult

If you want the user's browser to convert the HTML page or a part of it to another format and save it, you should look into the html5 File API or a Javascript framework, not ASP.NET MVC.

Upvotes: 1

Related Questions