我已經(jīng)成功創(chuàng)建了一個(gè)視圖來(lái)顯示一些投票記錄。但在同一個(gè)視圖上,我嘗試調(diào)用控制器上的另一個(gè)方法來(lái)導(dǎo)出這些記錄,但它只接收 0 作為參數(shù)。這是我的模型。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()); }這就是我試圖呼吁的行動(dòng)。[HttpPost]public IActionResult Export(int electionYear)這是我用來(lái)發(fā)布到控制器的表單。@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] 嘗試過(guò),它給了我 415 錯(cuò)誤
1 回答

料青山看我應(yīng)如是
TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超8個(gè)贊
Export
端點(diǎn)需要一個(gè)名為 electionYear
的表單值。但您的 <select>
沒(méi)有 name
(或任何 name
)。嘗試:
<select name="electionYear" class="form-control" asp-items="ViewBag.Election"></select>
- 1 回答
- 0 關(guān)注
- 156 瀏覽
添加回答
舉報(bào)
0/150
提交
取消