I have a View that contains automatically generated input
boxes of type text
. When I click the "Email Results" button, the code takes you over to the EmailResults Action within the CalculatedResults controller. So far, so good. But, even though I have FormCollection as a parameter in the EmailResults Action, it's coming through as null, and I don't know why. I need to be able to capture the text boxes from the form- please help!!. In my View code below, the generated text boxes are a little past halfway down.
My View Code
@using (Html.BeginForm("EmailResults", "CalculatedResults", FormMethod.Post, new { data_ajax = "false" }))
{
<table>
<thead>
<tr>
<td>Ingredient</td>
<td>Qty (gm)</td>
</tr>
</thead>
@foreach (var i in Model)
{
if (Convert.ToDecimal(i.Qty) < 0)
{
<tr>
<td style="border: 1px solid red; color: red;">@i.Ingredient</td>
<td style="border: 1px solid red; color: red;">@i.Qty</td>
</tr>
}
else if (Convert.ToDecimal(i.Qty) == 0m)
{
continue;
}
else
{
if (i.Ingredient.Contains("Active"))
{
<tr>
<td>@i.Ingredient<br />
<input type="text" name="actives" /></td>
<td>@i.Qty</td>
</tr>
}
else
{
<tr>
<td>@i.Ingredient</td>
<td>@i.Qty</td>
</tr>
}
}
}
</table>
}
<div style="float: left">
@Html.ActionLink("Email Results", "EmailResults", "CalculatedResults", new { crpk = @ViewBag.crpk }, new { data_icon = "arrow-r", data_role = "button" })
</div>
My Controller Code
public ViewResult EmailResults(int crpk, FormCollection collection)
{
CapWorxQuikCapContext context = new CapWorxQuikCapContext();
//List<string> variables = new List<string>();
//foreach (var item in Request.Form)
//{
// variables.Add(item.ToString());
//}
CalculatedResults cr = (from i in context.CalculatedResults where i.Pk == crpk select i).SingleOrDefault();
Helpers.Email.EmailResults(cr);
return View();
}
Here's a screenshot:
The formCollection will only come across when you submit the form to the controller. Either
<input type="submit" value="Email Results" />