c# - C# ASP.NET MVC 路由不返回成功页面的视图
问题描述
我有一个ActionResult
方法,最后我希望它返回成功页面。它击中了返回 View("ExportFile") 但什么也没发生。
这是我的操作方法:
[HttpPost]
//[ValidateAntiForgeryToken]
public ActionResult ExportFile(string[] years, string[] months, string[] radio, string[] emails, string acctNum)
{
// Is Account Number empty or Radio not selected
if (String.IsNullOrEmpty(acctNum.Trim()) && radio == null)
{
return Json(new { success = false, message = "* Please Enter Account Number\n\n * Please choose whether to download or email statements" });
}
if (acctNum == "")
{
return Json(new { success = false, message = "* Please Enter Account Number" });
}
else if (radio == null)
{
return Json(new { success = false, message = "* Please Choose whether To Download or Email" });
}
try
{
// If only account number is entered
if (years == null)
{
if (months == null)
{
using (var db = new FMBDBPRDEntities1())
{
allPaths = db.ClientStatement_Inventory
.Where(x => x.accountNum == acctNum)
.Select(c => c.statementPath).ToList();
}
if (allPaths.Count == 0)
{
return Json(new { success = false, message = $"There were no documents for Account#: {acctNum}" });
}
}
}
// If "Emailing Statements" is chosen
else if (radio[0] == "Email Statements")
{
// Make array of emails into List for sending in email
if (emails.ToString() != "")
{
var allEmails = emails[0].Split(',');
foreach (var email in allEmails)
{
if (emailValid.IsMatch(email))
{
everyEmail.Add(email);
}
else
{
return Json(new { success = false, message = $"* Not valid email address: {email}.\n\n * Please double check and try again." });
}
}
MemoryStream output = new MemoryStream();
List<string> distinctFiles = allPaths
.GroupBy(x => x.Split(new char[] { '\\' }).Last())
.Select(x => x.First())
.ToList();
using (ZipFile zip = new ZipFile())
{
zip.AddFiles(distinctFiles, @"\");
zip.Save(output);
output.Position = 0;
var attachmentResult = output.Length;
if (attachmentResult > 24500000)
{
return Json(new { success = false, message = "* Email attachment is too large.\n\n * Please select Download to download your files. " });
}
else
{
return View("ExportFile");
//DBQueries.SendEmail(everyEmail, output, fromAddress, "Client Statement Reports", "", true);
}
最后 "return View("ExportFile") 不会返回我的视图调用ExportFile
。动作名称和返回视图需要是相同的名称对吗?
解决方案
推荐阅读
- javascript - 如何从包含日期范围的字符串中提取年份 [Typescript/Angular]
- swift - 如何在 iOS 13 上共享文本和 URL 到提醒事项
- excel - Excel 多级数组公式与部分字符串匹配以求和结果单元格
- mongodb - 基于ObjectID的Mongodb Aggregation中的查询问题
- reactjs - React 函数的返回类型是什么
- ios - 提交到 AppStore Connect 时不支持 iOS 13
- angular - Angular 8后退按钮和参数
- python - Python 访问从导入的函数返回元组
- python - 由于“断言失败”而导致屏蔽失败......sameSize
- database - Csharp中的sqldataAdapter以更简单的方式?