【发布时间】:2020-02-05 15:38:52
【问题描述】:
我目前正在尝试将 ModelClass(FileInfo) 列表发布到我的控制器,但提交似乎根本没有调用控制器,即使在我调试时,该过程也不会进入我的控制器操作,如下是我的查看代码(claimdocumentform.cshtml),
@model IList<PIBSSBus.DomainModels.FileInfo>
<form method="POST" enctype="multipart/form-data">
<table class="table table-striped table-hover table-bordered" id="sample_editable_1">
<thead>
<tr>
<th> Document</th>
<th> Submitted </th>
<th> Date Submitted </th>
<th> # </th>
</tr>
</thead>
<tbody>
<tr>
<td> <input type="text" placeholder="title" asp-for="@Model[0].Title" value="enter"> </td>
<td><input type="text" placeholder="Description" asp-for="@Model[0].Description" value="enter1"> </td>
<td> </td>
<td>
<input type="file" class="" asp-for="@Model[0].File" value="Upload">
</td>
</tr>
<tr>
<td> <input type="text" placeholder="title" asp-for="@Model[1].Title" value="enter2"> </td>
<td><input type="text" placeholder="Description" asp-for="@Model[1].Description" value="enter3"> </td>
<td> </td>
<td>
<input type="file" class="" asp-for="@Model[1].File" value="Upload">
</td>
</tr>
@* @Html.AntiForgeryToken();*@
</tbody>
</table>'
<button type="submit" asp-controller="Claims" asp-action="Wazobia" class="btn green button-submit">
Submit
<i class="fa fa-check"></i>
</button>
</form>
这是我的控制器
public IActionResult claimdocumentform()
{
//PIBSSBus.DomainModels.FileInfo something = new PIBSSBus.DomainModels.FileInfo();
// IList<PIBSSBus.DomainModels.FileInfo> filess =new List<PIBSSBus.DomainModels.FileInfo>();
return View();
}
// [ValidateAntiForgeryToken]
[HttpPost]
public IActionResult Wazobia(IList<PIBSSBus.DomainModels.FileInfo> fam)
{
return View();
}
这是我的模型类
public class FileInfo
{
public string Title { get; set; }
public string Description { get; set; }
[DataType(DataType.Upload)]
public IFormFile File { get; set; }
}
我试图将包含两行的 FileInfo 类列表传递给我的控制器操作 Wazobia 但它根本不调用该操作的问题,请帮助
【问题讨论】:
-
我尝试了相同的代码,它运行良好。
asp-controller正确吗?你能不能在浏览器中按F12键检查你的开发工具的网络选项卡,然后查看请求是否发送。 -
@XingZou 1)。所以你的意思是,FileInfo 列表是在 fam 列表中的控制器操作 Wazobia 中收到的?因为我自己甚至根本没有进入控制器操作“Wazobia”,所以浏览器只会继续加载,直到它带来错误 2)。您是否像我在“claimdocumentform”控制器操作中那样返回了没有模型类的视图?
-
是的...所以我建议你检查你的浏览器 F12 网络标签
-
点赞i.stack.imgur.com/JS2KG.png看看你发了什么样的请求
-
@XingZou 这是错误imgur.com/a/FFZCj6q
标签: asp.net-core-2.2