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

1

12

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

Saltatorial answered 5/9, 2012 at 6:57 Comment(1)
You can see the answer of a similar question: #20336184Lian
E
20

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

Encomium answered 5/9, 2012 at 7:1 Comment(2)
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 .Saltatorial
What about returning FileResult with some notification message to show up?Chatham

© 2022 - 2024 — McMap. All rights reserved.