亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將選擇/下拉項的值傳遞給控制器??僅接收 0

將選擇/下拉項的值傳遞給控制器??僅接收 0

C#
慕慕森 2023-12-17 16:51:17
我已經成功創建了一個視圖來顯示一些投票記錄。但在同一個視圖上,我嘗試調用控制器上的另一個方法來導出這些記錄,但它只接收 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>


查看完整回答
反對 回復 2023-12-17
  • 1 回答
  • 0 關注
  • 170 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號