ViewModel:
public class ViewModel
{
public IList<Car> Cars { get; set; }
}
Model:
public class Car
{
int id { get; set };
string Color { get; set };
}
Post Action:
public ActionResult Select(ViewModel model)
{
foreach(var car in model.Cars)
{
carId = car.Id;
// more code...
}
return RedirectToAction("one","two",new { carId });
}
How to access for this element? Is this right?
Carsis a list ofCarobjects, it doesn't have anIdproperty. You need to access items on the list in order to get car's idsIt's hard to know what you specifically want to do. Do you have a single element on the list? Then something like this would do the trick
Do you need to iterate over elements in the list. Then you need to use a
foreachloopIf you need to select ALL ids then something like this would do the trick