c# - 在 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)
}
}
NextController.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);
推荐阅读
- powershell - 使用 PowerShell 从数组中提取特定字符串
- javascript - '"openURL"' 类型的参数不能使用 Jest 分配给 'never' 类型的参数
- python - 如何处理页面中的不同元素(国家天气)以进行网页抓取
- flutter - Flutter:使用 socket.io 将 un ascii 字符发送到服务器
- chilkat - 获取 Chilkat 版本
- vue.js - 无法更正错误以加载
Vue 风格 - python - VS Code 不会改变 python 环境
- python - 是否可以使用 Python 更改多个 Facebook 帖子的隐私设置?
- node.js - passport.authenticate("local")(req, res, function () {} 块没有被执行
- javascript - 使用 Vue.js 在 Janus 上流式传输