How to return an error message from a FileResult method in an 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 satisfied! So how can we only return the file from this method ?! Thnks

+4
source share
1 answer

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

+11
source

Source: https://habr.com/ru/post/959188/


All Articles