Come 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);
}
It should be done better so
Public ViewResult GiveMeFruit(Person person, IFruit fruit){
person.Fruits.Add(fruit);
ViewData.Person = person;
View(ViewData);
}
I tried the correct binding to models before, but I could not get it to work correctly. All examples show how it works with one extremely simple type, but not with several complex types. How does the model linker know which field is for which type? What to do if there are fruits1 and fruits2? How should a binder know which specific type to use for my IFruit interface? In addition, I am wondering how this will work if I want to give IEnumerable fruits for my Face.
source
share