【发布时间】: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