Roll with me and imagine the following example:
Public ViewResult GiveMeFruit(int personId, string personName, int personAge, int fruitId){
Person person = PersonService.GetPerson(personId);
person.Name = personName;
person.Age = age;
person.Fruits.Add(FruitService.GetFruit(fruitId));
ViewData.Person = person;
View(ViewData);
}
This should be done better like so
Public ViewResult GiveMeFruit(Person person, IFruit fruit){
person.Fruits.Add(fruit);
ViewData.Person = person;
View(ViewData);
}
I tried proper modelbinding earlier but I couldn't get it to work properly. All the examples show you how it works with one extremely simple type, never with multiple, complex types. How would the modelbinder know what field is for what type? What if there is a fruit1 and a fruit2? How would the binder know what concrete type to use for my IFruit interface? Furthermore I wonder how it would work if I want to give an IEnumerable fruits to my Person.