在 Razor 视图中使用 @Html.Action 成功转到新控制器,但在执行控制器后不会转到新控制器的视图



我正在使用MVC .net框架,我对 asp.net mvc很陌生,提前道歉。 我的查询是我能够在我的第一个控制器和视图中成功加载 csv 文件。从我的第一个视图,然后我转到我的NextController然后进行主要处理。直到这里一切都很好。从这里开始,我现在必须将其移动到下一个控制器的视图,FxProcess.相反,它返回到现有视图并抱怨新模型FxOrder的命名空间问题。我哪里出错了?以下是我的控制器和视图:

首页控制器.cs

public class HomeController : Controller
{
// GET: Home
public ActionResult Upload()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Upload(HttpPostedFileBase upload, SecTypeDetails secTypeUsed)
{
if (ModelState.IsValid)
{
if (upload != null && upload.ContentLength > 0)
{
if (upload.FileName.EndsWith(".csv"))
{
var csvParser = new TextFieldParser(upload.InputStream);
var fileName = upload.FileName;
var newview = new Trade0Tron.web.Models.SecTypeDetails { sectype = secTypeUsed.sectype, csvParser = csvParser, fileName = fileName };
return View(newview);
}
else
{
ModelState.AddModelError("File", "This file format is not supported");
return View();
}
}
else
{
ModelState.AddModelError("File", "Please Upload Your file");
}
}
return View();
}
}

上传.cshtml

@model Trade0Tron.web.Models.SecTypeDetails
@using System.Data;
<h2>Upload File</h2>
@using (Html.BeginForm("Upload", "Home", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary()
<div class="row">
<div class="col-md-4">
<div class="form-group">
<input type="file" id="dataFile" name="upload" />
</div>
<div class="form-group">
<input type="submit" value="Upload" class="btn btn-default" />
</div>
</div>
<div class="col-md-8">
<div class="form-group">
Select SecType to run
</div>
<div class="form-group">
@Html.EnumDropDownListFor(
x => x.sectype,
new { @class = "form-control" })
</div>
</div>
</div>
if (Model != null)
{
@Html.Action("FxProcess", "Next", Model)
}
}

下一个控制器.cs

public class NextController : Controller
{
public ActionResult FxProcess(SecTypeDetails secTypeUsed)
{
var wk = new Work();
var fxOrder = wk.FxFileProcessing("", secTypeUsed.fileName, "csv", secTypeUsed.sectype.ToString(), false, secTypeUsed.csvParser);
return View("FxProcess", fxOrder);
}
}

而对应的CSHTML如下

@model Models.Fx.FxOrder
@using System.Data;
<h2>Upload File</h2>
@using (Html.BeginForm("FxProcess", "FxTrade"))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary()
if (Model != null)
{
@Html.Action("GetResult", "FxResult", Model)

理想情况下,我希望NextController操作的结果转到其相应的视图,然后转到结果控制器。它再次具有显示结果的结果视图。另请注意,NextController 有一个新的模型 Models.Fx.FxOrder。

路由可能取决于文件夹结构。返回 View(( 时,您可以指示完整路径。return View("~/Views/Next/FxProcess", fxOrder);

最新更新