【问题标题】:ASP.NET I cannot get the model to bring data back to the controller. It is always 0ASP.NET 我无法让模型将数据带回控制器。它始终为 0
【发布时间】:2020-10-01 16:04:11
【问题描述】:

所以我一直在研究这个问题,但无法弄清楚为什么我的数据总是为 0。NumJuror 只是一个模型,用于从视图中保留我需要的单个 int。

我的控制器:

        [HttpPost]
    public IActionResult Index(NumJuror model)
    {
        return RedirectToAction("ListPool", model.numberOfJurors);
    }

    [HttpGet]
    public IActionResult ListPool(int numberOfJurors)
    {
        JurySQLDAO jurySQLDAO = new JurySQLDAO();
        JuryPool jury = new JuryPool(); 
        int rows = jurySQLDAO.GetRows();
        RandomID randomID = new RandomID();
        for (int i = 0; i < numberOfJurors; i++)
        {
            Juror juror = new Juror();
            juror = jurySQLDAO.GetJuror(randomID.getRandomID(rows));
            jury.Pool.Add(juror);
        }

        return View(jury);
    }

我的观点是这样的:

    @model Iudices2._0.Models.NumJuror
@{
    ViewData["Title"] = "Index";
}

<h2>Jury Selection Portal</h2>
<p>Please enter the number of jurors need for this pool:</p>
<form asp-controller="Home" asp-action="Indexview " method="post">
    <p>
        <input type="number" asp-for="numberOfJurors">
    </p>
    <input type="submit" value="Submit">
</form>

我已经调试了好几次,无论我在索引中放什么,模型总是返回为 0,但模型状态有效。

【问题讨论】:

    标签: c# asp.net .net asp.net-mvc


    【解决方案1】:

    尝试将其更改为:

    <form asp-controller="Home" asp-action="Index" method="post">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-01
      • 2021-02-24
      • 2021-04-05
      相关资源
      最近更新 更多