My question is similar to Engram here , but my question goes a bit further. The way I intend to work is a text box asking how many records the user will make. After entering the number, I need to create many more text fields to allow entries (and then repeat the same process with these text fields, but first the steps for the child ...) I tried to collect the keys in the message, but it only returns in the initial The text field asks for the number of records. I'm still trying to understand MVC, and the tutorials / videos still haven't delved into that. Again, I know that this is probably something I could use with jQuery, but I would still be stuck in the same situation.
This is the controller I use:
[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");
}
And this is my 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"]) %>
Is there something that I forget without understanding, or should I leave while I am on it, because it seems that I will never get it?
Thanks in advance for any help - I'm just trying to learn as much as possible.
source
share