我使用的是MVC .net框架,对asp.net mvc很陌生,提前道歉。我的疑问是,我能够在我的第一个控制器和视图中成功加载一个csv文件。在我的第一个视图中,我然后进入我的 NextController 然后进行主要处理。直到这里,一切都很好。从这里开始,我现在要把这个移到我下一个控制器的视图中。FxProcess. 相反,它返回到现有视图,并抱怨新模型的命名空间问题。FxOrder. 我到底哪里出错了?这是我的控制器和视图。
HomeController.cspublic 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;
Upload File
@using (Html.BeginForm("Upload", "Home", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary()
Select SecType to run
@Html.EnumDropDownListFor(
x => x.sectype,
new { @class = "form-control" })
if (Model != null)
{
@Html.Action("FxProcess", "Next", Model)
}
}
NextController.cspublic 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;
Upload File
@using (Html.BeginForm("FxProcess", "FxTrade"))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary()
if (Model != null)
{
@Html.Action("GetResult", "FxResult", Model)
我理想中的结果是NextController 动作进入其对应的视图,然后进入结果控制器。其中又有一个结果视图来显示结果。另外注意NextController有一个新的模型Models.Fx.FxOrder。