I have a couple Hidden form fields that are not being sent when I submit the form? I use the Html Helpers to add the form the page…
<%using (Html.BeginForm("UpdateXML", "PatientACO", new { template = (int)Model, PopPatId = TempData["POPPATID"]}, FormMethod.Post, new { name = "editTemp", id = "temp1" }))
Response.Write("<table width=\"500\" class=\"odd\">");
Html.Hidden("encounter", encounter);
Html.Hidden("AddEnc", encflag);
Response.Write("</table>"); %>
Here is the method in my controller…
public ActionResult UpdateXML(int template, int PopPatId, FormCollection formCollection)
{
foreach (var key in formCollection.Keys)
{
if (key.ToString() == "deactivate")
{
((XmlElement)node.SelectSingleNode("//template/elements/element[@name=\"Active\"]")).SetAttribute("value", value);
if (value == "N")
{
dateIn = DateTime.Now.ToString("dd-MMM-yy");
}
}
if (key.ToString() == "AddEnc")
{
if(formCollection[key.ToString()]=="ADDENC")
((XmlElement)node.SelectSingleNode("//template/elements/element[@name=\"FOCUSED_READMISSIONS_ID\"]")).SetAttribute("value", "0");
}
}
}
Those two If statements never hit. Also, when I look at the formCollection Object, I can see that those two fields aren’t in there. How can I make sure that my hidden fields are submitted with the rest of the form?
You have a few things wrong in that code. If you’re trying to mix html with server-side code you shouldn’t use
Response.Write. Also, you need to place the contents of the form inside braces. Try this: