11

I have a fileresult method in asp.net mvc4 that returns a report in an excel file. Now how can i return an error message from this method if my conditions are not met !! Since we can only return a file from this method ?! Thnks

Ashkan
  • 616
  • 1
  • 9
  • 15
  • 1
    You can see the answer of a similar question: http://stackoverflow.com/questions/20335684/asp-net-mvc-4-fileresult-in-error – Believe2014 Apr 30 '14 at 19:38

1 Answers1

19

You can change signature of action method to public ActionResult MyMethod() and return FileResult when ModelState.IsValid==true and ViewResult when ModelState.IsValid==false

Kirill Bestemyanov
  • 11,946
  • 2
  • 24
  • 38
  • thnks Kirill , Actually I already solved my problem by returning a plain text which is not a good approach . But I didnt know I could return a file from a an ActionResult . Thnks . – Ashkan Sep 05 '12 at 07:38
  • What about returning FileResult with some notification message to show up? – dellos Mar 02 '22 at 07:46