我的问题与 Engram's here类似,但我的问题更进一步。我打算让它工作的方式是我有一个文本框询问用户要输入多少条目。在他们输入数字后,我需要创建更多的文本框以允许输入(然后对这些文本框重复相同的过程,但首先是婴儿步骤......)我尝试收集帖子上的密钥,但它只返回初始文本框询问条目数。我仍在尝试掌握 MVC,到目前为止的教程/视频还没有深入研究它。再说一次,我知道这可能是我可以使用 JQuery 处理的事情,但我仍然会陷入同样的境地。
这是我正在使用的控制器:
[AcceptVerbsAttribute("POST")]
public ActionResult Create(int tbxNumberOfExercises)
{
ViewData["number"] = tbxNumberOfExercises;
foreach (var key in Request.Form.Keys)
{
string keyString = key.ToString();
if (keyString.StartsWith("tbox_exercise", StringComparison.OrdinalIgnoreCase))
{
string recNum = keyString.Substring(13, keyString.Length - 13);
string approvedKey = Request.Form["tbox_exercise" + recNum];
int number;
int.TryParse(approvedKey, out number);
}
}
return View("Create");
}
这是我的aspx:
<form action="/CreateWorkout/Create" method="post">
Number of Exercises:
<%= Html.TextBox("tbxNumberOfExercises") %>
<br />
<br />
<input type="submit" value="Set Exercise Number" />
</form>
<% if (ViewData["number"] != null)%>
There are this many:<%=Html.Encode(ViewData["number"])%>
<br />
and this line should show up
<% if (ViewData["number"] != null)
{
int max = (int)ViewData["number"];
for (int i = 0; i < max; i++)
{%>
<br />
<br />
<%= Html.TextBox("tbox_exercise" + i) %>
<% }
} %>
<% if (ViewData["s"] != null) %>
<%=Html.Encode(ViewData["s"]) %>
有没有什么我忽略了,没有理解,或者我应该在我做的时候放弃,因为我似乎永远不会得到它?
在此先感谢您的帮助-我只是尽力学习。