I am writing an ASP.NET MVC application. I am new, so I am sure it is very simple. I referred to ASP.NET MVC - how to get flag values in a message , but the code is no longer available, making it next to useless.
Here is my view:
@using (@Html.BeginForm("Promote", "FPL", FormMethod.Post))
{
<div data-role="fieldcontain">
<fieldset id="PromotionInfo" name="PromotionInfo">
<legend><b>@Model.itemType Promotion Details</b></legend>
<label for="TargetDate">Target Date: </label>
<input type="date" id="TargetDate" data-role="datebox" data-options='{"mode": "flipbox"}' />
<label for="EmailCC">Email cc List: </label>
<input type="email" id="EmailCC" />
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<legend>Choose Destination Server(s): </legend>
@foreach (DataRow server in Model.destinationServerList.Rows)
{
<label for="@server.ItemArray[0]">@server.ItemArray[1]</label>
<input type="checkbox" name="destinationServerSID" id="@server.ItemArray[0].ToString()" />
}
</fieldset>
</div>
</fieldset>
</div>
<input type="submit" value="Submit" />
}
And here is my controller:
public ActionResult Promote(string id)
{
return View(item);
}
[HttpPost]
public ActionResult Promote(FormCollection collection)
{
try
{
string[] test = collection.GetValues("destinationServerSID");
}
catch (Exception ex)
{
return null;
}
}
The variable test [] contains an array of two elements, both of which have the value "on", however, my list of elements is longer than 2 elements. It simply contains "on" for each value you select, but it does not have the value "off". I need the actual value of the checkbox (id field).
source
share