【发布时间】:2016-06-21 09:05:48
【问题描述】:
我有一个视图要求用户上传 Excel 文件,我的控制器读取 excel 文件并将结果作为模型返回。该模型包含名为 AssingednUmbers public List<String> AssignedNumbers { get; set; }
值显示在查看页面上。在这一步之前一切正常。现在我有一个名为 DownloadFile 的方法
[HttpPost]
public FileResult DownloadFile(OnvoyModel model)
它有一个模型条目并返回 csv 文件。转换和一切工作正常。但是我传递给 DownloadFile 的模型总是空的。上传 Excel 文件并在用户单击下载按钮时在页面上返回结果(数字)后,控制器调用 DownloadFile 方法,但模型为 Null。如何将模型及其内部的列表从之前传回我的控制器
// Looping through my List that comes from the Model
<table>
@foreach (var Number in Model.AssignedNumbers) {
<li>
@Number
</li>
@Html.HiddenFor(x => x.AssignedNumbers);
}
</table>
<td>
///Submitting to download the new list and calling the Method
@using (Html.BeginForm("DownloadFile", "PhoneBookProcessing", FormMethod.Post))
{
@Html.Action("DownloadFile", new { model = Model.AssignedNumbers })
}
<div class="form-group">
<button class="btn btn-default" type="submit">Download This File</button>
</div>
}
型号
public class OnvoyModel
{
public List<String> AssignedNumbers { get; set; }
}
【问题讨论】:
标签: asp.net-mvc view controller