I have searched for this, and found several solutions, but none seem to work for me.
I'm using Razor to build an MVC view. The model I'm passing in is defined as follows:
public class ActiveProxiesDTO
{
/// <summary> error message returned by the transaction </summary>
public string ErrorMsg { get; set; }
/// <summary> List of proxies returned by the transaction </summary>
public List<ActiveProxiesDetailDTO> ActiveProxies { get; set; }
}
/// <summary> A single proxy </summary>
public class ActiveProxiesDetailDTO
{
/// <summary> Proxie's PERSON id </summary>
public string ProxyId { get; set; }
/// <summary> Proxie's First Name </summary>
public string FirstName { get; set; }
/// <summary> Proxie's Last Name </summary>
public string LastName { get; set; }
/// <summary> Proxie's email address </summary>
public string EmailAddress { get; set; }
/// <summary> Does user want to reset this proxy's password? "Y" or "N"</summary>
public bool Reset { get; set; }
}
In the action method that invokes the view I set the "Reset" bool to false for all items in the list.
My view is defined as follows:
@model Ellucian.Colleague.Dtos.Base.M32.ActiveProxiesDTO
<snip>
@using (Html.BeginForm("PostResetProxy", "Core", FormMethod.Post, new { Area = "M32" }))
{
@Html.AntiForgeryToken()
<!-- make sure all fields get returned to the next controller action method -->
<input type="hidden" name="ErrorMsg" value="@Model.ErrorMsg" />
<div class="dataentry">
Proxies:
<br />
<table>
<tr>
<th>Reset?</th> <th>Name</th> <th>Email Address(to send new password)</th>
</tr>
@for (int i = 0; i < Model.ActiveProxies.Count; i++)
{
<tr>
<td>
<!-- make sure all data bind to the model being passed to the next controller action method -->
<input type="hidden" name="ActiveProxies[@i].ProxyId" value="@Model.ActiveProxies[i].ProxyId" />
<input type="hidden" name="ActiveProxies[@i].FirstName" value="@Model.ActiveProxies[i].FirstName" />
<input type="hidden" name="ActiveProxies[@i].LastName" value="@Model.ActiveProxies[i].LastName" />
<!-- checkboxes require both a hidden and non-hidden input element -->
<input type="hidden" name="ActiveProxies[@i].Reset" value="@Model.ActiveProxies[i].Reset" />
<input type="checkbox" name="ActiveProxies[@i].Reset" value="true" />
</td>
<td>
@{ var displayName = Model.ActiveProxies[i].FirstName + " " + Model.ActiveProxies[i].LastName; }
@displayName
</td>
<td>
<input type="text" name="ActiveProxies[@i].EmailAddress" value="@Model.ActiveProxies[i].EmailAddress" />
</td>
</tr>
}
</table>
<br />
<input type="submit" />
<snip>
for now, the action method handling the POST is simply:
[HttpPost]
public ActionResult PostResetProxy( ActiveProxiesDTO formData )
{
return Redirect(Url.Action("Index", "Home", new { Area = "" }));
}
I set a breakpoint at the return statement and check the contents of formData. Everything looks correct: The entire ActiveProxies list is present, If I enter email addresses on the form they post correctly to the proper entry of the list. The problem is that, whether I check the "reset" box or not, the value is always passed back as false.
I've tried using Html.CheckBox and Html.CheckBoxFor in various ways as described elsewhere in this forum, but with no success. I've tried using string instead of bool for the checkbox value, but that also failed. I'm out of ideas. Anyone see what I'm doing wrong? -- TIA Gus
Aucun commentaire:
Enregistrer un commentaire