我正在尝试处理我正在开发的申请表的其中一个部分的错误,以解释我的问题,下面的屏幕截图显示了此部分的工作流程:
当您首次导航到显示此屏幕的部分时,您从下拉列表中选择了一个选项,然后单击下一步。
当您单击下一步时,所选选项的表单值将生成如下:
当您更改选项时出现问题,当生成新选项表单值时,生成前一个选项的错误,如下所示:
解释当点击下一个或更改按钮时的一些逻辑,它会回复到actionresult中相应的applycontroller中的actionresult,它将选项值发布到web api,它将数据保存到数据库,下面的代码是执行此任务:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> AdmissionsTest(AdmissionsTestViewModel model, ApplyService service, string programmeDesc, int? programmeId, FormCollection formCollection)
{
Guid applicationId = (Guid)TempData["ApplicationId"];
TempData["ApplicationId"] = applicationId;
model.ApplicationValidations = (ICollection<ApplicationValidation>)TempData["ApplicationValidations"];
TempData["ApplicationValidations"] = model.ApplicationValidations;
model.ApplicationProgrammeDetails = DependencyResolver.Current.GetService<ApplicationProgrammeDetailsViewModel>();
if (programmeId != null)
{
Programme programme = service.GetProgramme(model.ProgrammeId);
model.ApplicationProgrammeDetails.ProgrammeDesc = programme.ProgrammeDesc;
}
else
{
model.ApplicationProgrammeDetails.ProgrammeDesc = programmeDesc;
}
foreach (var item in formCollection.AllKeys)
{
if ((model.AdmissionsTestOptionId == null) && (item.ToLowerInvariant().StartsWith("submitbuttonnext") || (item.ToLowerInvariant().StartsWith("submitbuttonchange"))))
{
model.ApplicationId = applicationId;
model.NavButton = "10";
await _client.PostAsJsonAsync("api/ApplicationAdmissionsTestDetail/UpdateApplicationAdmissionsTestDetail", model)
.ContinueWith((postTask) => postTask.Result.EnsureSuccessStatusCode());
return View("AdmissionsTest", model);
}
if ((model.AdmissionsTestOptionId == 1) && (item.ToLowerInvariant().StartsWith("submitbuttonnext") || (item.ToLowerInvariant().StartsWith("submitbuttonchange"))))
{
model.ApplicationId = applicationId;
model.NavButton = "10";
await _client.PostAsJsonAsync("api/ApplicationAdmissionsTestDetail/UpdateApplicationAdmissionsTestDetail", model)
.ContinueWith((postTask) => postTask.Result.EnsureSuccessStatusCode());
return View("AdmissionsTest", model);
}
if ((model.AdmissionsTestOptionId == 2) && (item.ToLowerInvariant().StartsWith("submitbuttonnext") || (item.ToLowerInvariant().StartsWith("submitbuttonchange"))))
{
model.ApplicationId = applicationId;
model.NavButton = "10";
await _client.PostAsJsonAsync("api/ApplicationAdmissionsTestDetail/UpdateApplicationAdmissionsTestDetail", model)
.ContinueWith((postTask) => postTask.Result.EnsureSuccessStatusCode());
return View("AdmissionsTest", model);
}
if ((model.AdmissionsTestOptionId == 3) && (item.ToLowerInvariant().StartsWith("submitbuttonnext")))
{
model.ApplicationId = applicationId;
await _client.PostAsJsonAsync("api/ApplicationAdmissionsTestDetail/UpdateApplicationAdmissionsTestDetail", model)
.ContinueWith((postTask) => postTask.Result.EnsureSuccessStatusCode());
if (model.NavButton == null) { model.NavButton = "11"; }
return NavigateToStage(model.NavButton);
}
if ((model.AdmissionsTestOptionId == 3) && (item.ToLowerInvariant().StartsWith("submitbuttonchange")))
{
model.ApplicationId = applicationId;
model.NavButton = "10";
await _client.PostAsJsonAsync("api/ApplicationAdmissionsTestDetail/UpdateApplicationAdmissionsTestDetail", model)
.ContinueWith((postTask) => postTask.Result.EnsureSuccessStatusCode());
return View("AdmissionsTest", model);
}
}
//save
string dateGMATTaken = model.DateGMATTakenDay + "/" + model.DateGMATTakenMonth + "/" + model.DateGMATTakenYear;
string dateGRETaken = model.DateGRETakenDay + "/" + model.DateGRETakenMonth + "/" + model.DateGRETakenYear;
DateTime dateOfGMATTestTaken;
DateTime dateOfGRETestTaken;
if (DateTime.TryParse(dateGMATTaken, out dateOfGMATTestTaken))
{
model.GMATDateTaken = dateOfGMATTestTaken;
}
else
{
model.GMATDateTaken = null;
}
if (DateTime.TryParse(dateGRETaken, out dateOfGRETestTaken))
{
model.GREDateTaken = dateOfGRETestTaken;
}
else
{
model.GREDateTaken = null;
}
model.ApplicationId = applicationId;
await _client.PostAsJsonAsync("api/ApplicationAdmissionsTestDetail/UpdateApplicationAdmissionsTestDetail", model)
.ContinueWith((postTask) => postTask.Result.EnsureSuccessStatusCode());
//redirect based on submit
if (model.NavButton == null) { model.NavButton = "11"; }
return NavigateToStage(model.NavButton);
}
我已经使用断点测试了actionresult,看看它是否可能会进入最终提交操作但是到目前为止它似乎仍然停留在actionresult中我还使用了fiddler来查看web api上的submit方法是否是被称为这也是空白。
有没有人对为什么会发生这种情况有任何想法?
提前感谢您的建议。
答案 0 :(得分:0)
已修改了返回值,因此现在使用已解决错误的return View()
而不是返回return RedirectToRoute()