I am trying to get the selected checkboxes value
this are my models,
public class VehicleViewModel : Vehicle
{
[Display(Name = "Vehicle Type")]
[Required( ErrorMessage = "{0} is required.")]
public string VehicleTypeName { get; set; }
[Display(Name = "Location")]
[Required(ErrorMessage = "{0} is required.")]
public string LocationName { get; set; }
public IEnumerable<AssignProductsViewModel> AssignedProducts { get; set; }
}
public class AssignProductsViewModel
{
public long ProductID { get; set; }
public string ProductName { get; set; }
}
here's my razor view
@foreach (var item in Model.AssignedProducts)
{
<tr>
<td>
<input type="checkbox" value ="@item.ProductID"/>
</td>
<td>
@Html.DisplayFor(model => item.ProductName)
</td>
</tr>
}
and here's my controller
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult NewVehicle(VehicleViewModel vehicleViewModel, string selected)
{
//Do something with the string here
return View();
}
I know I need to pass the selected check boxes value to a string using javascript and pass the string to a controller. But i have no idea how to do it since I'm a newbie in javascript and MVC.