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

邮差的信 提交于 2019-12-23 08:49:41

问题


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:


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



来源:https://stackoverflow.com/questions/12276044/how-to-return-error-message-from-fileresult-method-in-asp-net-mvc-4-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!