I'm trying to get the value of some checkbox which is selected using ajax and jquery. Right now I have all items listed on my site, but I want to let user to check the checkbox to get the selected items.
Controller:
[HttpGet] public JsonResult getCategoryItems(){}
How can it be done?
View:
@for (int i = 0; i < Model.CarsCount.Count(); i++)
{
var cars = Model.CarsCount.ElementAt(i);
<span class="label label-info">
@cars.CategoryName <span class="badge">@cars.CategoryCount</span
</span>
@Html.CheckBox(cars.CategoryName, cars.isChecked, new { id = "carsCheckbox"})
}
As you can see, the code above is just counting the items in category to list as checkbox. I just want to let a user to check the checkboxes, however so user can get the items by check an item from checkboxes.
private IEnumerable<CarViewModel> GetListOfCars()
{
var listOfcars = this.Data.cars.All()
.Select(t => new CarViewModel
{
Id = t.Id,
Title = t.Title,
Price = t.Price ,
FileName = t.FileName
});
return listOfcars;
}
CheckBox()is generating duplicatenameattributes with no relationship to your model and duplicateidattributes which is invalid html. I cannot understand what your trying to achieve with this code.getCategoryItems()using ajax and return some data?