我已經成功創建了一個視圖來顯示一些投票記錄。但在同一個視圖上,我嘗試調用控制器上的另一個方法來導出這些記錄,但它只接收 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 關注
- 170 瀏覽
添加回答
舉報
0/150
提交
取消