Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 asp.net mvc4 中有一个 fileresult 方法,它在 excel 文件中返回报告。现在,如果不满足我的条件,我如何从该方法返回错误消息!因为我们只能从这个方法返回一个文件?!谢谢
您可以将动作方法的签名更改为public ActionResult MyMethod()并返回FileResult何时ModelState.IsValid==true和ViewResult何时ModelState.IsValid==false
public ActionResult MyMethod()
FileResult
ModelState.IsValid==true
ViewResult
ModelState.IsValid==false