如何在下面的代码中验证“成功”是真还是假?我已尝试使用以下代码,但它不起作用:
if (result["success"].Equals(false)) throw new Exception(result["message"].ToString());
if (result["message"].ToString().Contains("maximum limit reached")) throw new Exception(result["message"].ToString());
这是我的行动:
[HttpPost]
public ActionResult PostFile(string NewFileName, string FileNumber)
{
try
{
var result = ((JsonResult)(SaveFile(NewFileName, FileNumber))).ToDictionary();
if (result.Keys.Contains("message")) throw new Exception(result["message"].ToString());
//if (result["success"].Equals(false)) throw new Exception(result["message"].ToString());
return Content("success");
}
catch (Exception ex)
{
return Content(ex.ToString());
}
}
public ActionResult SaveFile(string status, string FileNumber)
{
try
{
var currentPath = ConfigurationManager.AppSettings["FilePath"];
string filename = FileNumber + ".pdf";
var ext = UploadHandler.SaveUploadedFile(Path.GetDirectoryName(currentPath), filename);
return Json(new { success = true }, "text/html");
}
catch (Exception ex)
{
return Json(new { success = false, message = ex.Message }, "text/html");
}
}
任何帮助深表感谢