C
C#15mo ago
palapapa

❔ What is the purpose of `ModelBindingContext.Model`, `ModelName`, and `ModelBinderAttribute.Name`?

The docs are very unclear about this. If I should set ModelBindingContext.Result to ModelBindingResult.Success(result), then what is the point of setting ModelBindingContext.Model? Also, what is the point of ModelBindingContext.ModelName? I don't understand what its value is supposed to be from the docs alone. From my understanding, the "model" being referred to here is my custom model class, then how am I supposed to "look up values in IValueProvider during model binding," if the model is the thing I need to set? This also brings it to my last question, which is what exactly is ModelBinderAttribute.Name setting?
2 Replies
palapapa
palapapaOP15mo ago
It seems that ModelName is just the argument name, and ModelBinderAttribute.Name and override that name. Since usually the argument name is the same as, say, some route data segment, by using ValueProvider.GetValue(context.ModelName), you can usually get the route data. I guess this is what the default model binder does, and of course this won't work with complex types. But I still don't understand what ModelBindingContext.Model is supposed to do though.
Accord
Accord15mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server