我的問題與Engram的here類似,但我的問題更進一步。我打算工作的方式是我有一個文本框詢問用戶要做多少條記錄。在他們輸入數字後,我需要創建更多的文本框以允許輸入(然後用這些文本框重複相同的過程,但是先要使用嬰兒步驟...)我嘗試收集帖子上的密鑰,但它只返回最初的文本框要求輸入的數量。我仍然試圖掌握MVC,目前爲止的教程/視頻還沒有深入研究。然後再次,我知道這可能是我可以使用JQuery處理的東西,但我仍然陷於同樣的情況。根據ASP.Net中的用戶輸入動態地填充表單MVC
這是我使用的控制器:
[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"]) %>
有我俯瞰,不理解的東西,或者我應該退出,而我因爲它似乎我永遠不會得到它?
在此先感謝您的幫助 - 我只是儘可能多地學習。