Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return error message from FileResult method in asp.net MVC 4 application?

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

like image 903
Ashkan Avatar asked Sep 05 '12 06:09

Ashkan


1 Answers

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

like image 100
Kirill Bestemyanov Avatar answered Oct 14 '22 07:10

Kirill Bestemyanov