我已经成功创建了一个视图来显示一些投票记录。但在同一个视图上,我尝试调用控制器上的另一个方法来导出这些记录,但它只接收 0 作为参数。这是我的模型。public class Vote { public int Id { get; set; } public int CPF { get; set; } public virtual Candidate Candidate { get; set; } public int CandidateID { get; set; } public DateTime Moment { get; set; }}这是我的索引。public async Task<IActionResult> Index() { var context = _context.Vote.Include(v => v.Candidate).Include(v => v.Candidate.Election); //This is going to be on the view for the user to select the year to export data ViewData["Election"] = new SelectList(_context.Election, "Id", "Year"); return View(await context.ToListAsync()); }这就是我试图呼吁的行动。[HttpPost]public IActionResult Export(int electionYear)这是我用来发布到控制器的表单。@model IEnumerable<Models.Vote>...//Here i show the votes and then below i show this form with the Elections<form asp-action="Export"> <div class="form-group"> <select class="form-control" asp-items="ViewBag.Election"></select> </div> <div class="form-group"> <input type="submit" value="Exportar" class="btn btn-default" /> </div></form>我用 [FormBody] 尝试过,它给了我 415 错误
1 回答
料青山看我应如是
TA贡献1772条经验 获得超8个赞
Export
端点需要一个名为 electionYear
的表单值。但您的 <select>
没有 name
(或任何 name
)。尝试:
<select name="electionYear" class="form-control" asp-items="ViewBag.Election"></select>
- 1 回答
- 0 关注
- 105 浏览
添加回答
举报
0/150
提交
取消