【发布时间】:2019-08-09 21:28:12
【问题描述】:
我想使用 CopytoAPResults 方法重新加载 TvrPrnetExcel,但视图未重定向到操作。我尝试使用另一个动作。它没有用。方法有效,但重定向无效。为什么?我该怎么办?:
这是我的操作:
public ActionResult TvrPrnetExcel()
{
return View();
}
[HttpPost]
public async Task<ActionResult> TvrPrnetExcel(FormCollection form)
{
.........
using (var db = new TVREntities()){
foreach (string i in ids)
{
var dataID = Convert.ToInt64(i);
TVRClip tvrClip = db.TVRClip.Where(x => x.TVRClipDataID == dataID).SingleOrDefault();
TVRPublicationProgram publicationProgram = db.TVRPublicationProgram.Where(x => x.TVRProgramID == tvrClip.TVRProgramID).FirstOrDefault();
using (var db2 = new MpnetContext())
{
tbl_APVideoResults APVideoResults = db2.tbl_APVideoResults.Where(x => x.APClipId == dataID).FirstOrDefault();
if (APVideoResults != null && APVideoResults.WMVFile != null)
{
pr.wmvFile = APVideoResults.WMVFile.ToString();
}
else
{
nonexist.Add(dataID);
pr.wmvFile = "";
}
}
pr.haberLink = "http://www.prnet.com.tr/wmv/" + pr.tarih.Substring(0, 2) + pr.tarih.Substring(3, 2) + pr.tarih.Substring(6, 4) + pr.wmvFile + ".mp4";
tVRClips.Add(pr);
}
}
Task t1 = Task.Factory.StartNew(() =>
{
CopytoAPResults(nonexist, form);
});
return View(tVRClips);
}
这是我的方法。
private ActionResult CopytoAPResults(List<long> nonexist, FormCollection form)
{
if (nonexist.Count()>0)
{
foreach (long i in nonexist){ }
}
return RedirectToAction("TvrPrnetExcel");
}
【问题讨论】:
-
你为什么要从一个新的
Task调用CopytoAPResults,然后忽略返回值?如果你总是执行return View(tVRClips);(你这样做)那么你没有重定向。 -
我想先发送
tvrClips查看。顺便说一句,我想运行CopytoAPResults方法,当该方法完成时,对象将被再次发送到查看。因为方法的工作需要很长时间。 -
这不是 MVC 的工作方式。您不能返回
View,然后“希望”之后会神奇地发送重定向。一个请求只能返回一个东西(一个视图或一个请求,不能同时返回)。
标签: c# asp.net asp.net-mvc model-view-controller