13

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

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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 .
What about returning FileResult with some notification message to show up?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.