Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将选择/下拉项的值传递给控制器仅接收0_C#_Asp.net Core_Controller_Entity Framework Core_Razor Pages - Fatal编程技术网

C# 将选择/下拉项的值传递给控制器仅接收0

C# 将选择/下拉项的值传递给控制器仅接收0,c#,asp.net-core,controller,entity-framework-core,razor-pages,C#,Asp.net Core,Controller,Entity Framework Core,Razor Pages,我已经成功创建了一个视图来显示来自votings的一些记录。但在同一个视图中,我尝试调用控制器上的另一个方法来导出这些记录,它只接收0作为参数 这是我的模型 public class Vote { public int Id { get; set; } public int CPF { get; set; } public virtual Candidate Candidate { get; set; } public in

我已经成功创建了一个视图来显示来自votings的一些记录。但在同一个视图中,我尝试调用控制器上的另一个方法来导出这些记录,它只接收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());
        }
这是我用来发布到控制器的表单

@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个错误

导出端点需要一个名为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>
<select name="electionYear" class="form-control" asp-items="ViewBag.Election"></select>