I have a problem in my application I am using MVC 3 with razor and i want to get the value of checked box in the form
@using (Html.BeginForm("ConfirmItemAvilabilty", "Order", FormMethod.Post, new { id = "frmConfirmAvilabilty", name = "frmConfirmAvilability" }))
{
foreach (OrderItem orderItem in orderAction.Order.OrderItems)
{
<div class="product">
<ul>
<li>
<div class="productImg">
<img src="@orderItem.Product.Image" width="100px" height="100px"/>
</div>
<div class="centered">
<a href="@orderItem.Product.Link" target="_blank">Link</a> <span>@orderItem.Product.TitleAr</span>
<span>@orderItem.Product.Price</span>
</div>
@if (currentUser.UserTypeEnum == UserTypeEnum.Reseller)
{
<div>
@Html.CheckBox("ChkConfirm", orderItem.IsAvailable, new { id="chkConfirm" ,@class="chkConfirm"})
@Html.Hidden("OrderItemId", orderItem.Id, new { id="hdnConfirm"})
</div>
}
</li>
</ul>
</div>
}
if (currentUser.UserTypeEnum == UserTypeEnum.Reseller)
{
<button>Confirm</button>
}
}
Simply i want to get the value of all checked checkboxs i tryed to create a model holding the value of my checkbox and the value of the hidden text below it
public class ItemOrderModel
{
public string ChkConfirm { get; set; }
public string OrderItemId { get; set; }
}
and in my controller i do the following but nothing happened
public ActionResult ConfirmItemAvilabilty(List<ItemOrderModel> OrderItems)
{
return View();
}
but orderItems always returns null, Can anyone help me in that?
----------------- Edit ------------------ Thank you Sam and Jesse
I Found a solution for my problem but I am facing another problem now first of all i solved my problem by changing in model view to be like that
public class ItemOrderModel
{
public List<bool> ChkConfirms { get; set; }
public List<string> OrderItemId { get; set; }
}
and change the checkbox name to be
@Html.CheckBox("ChkConfirms", orderItem.IsAvailable, new { id = "chkConfirm", @class = "chkConfirm" })
the problem now is when i submit i found two values false that is the actual representation of my checkboxs and two ids that's also the actual representation of my hidden fields "Correct scenario" when i check one of check boxs in the same form i found 3 result for the check box and 2 results for the hidden field Can any one help in that or have a solution