views:

178

answers:

1

Can anyone explain where the ModelName gets populated from?

Looked in MSDN documentation and no explaination here. I am creating a custom model binder and within it I get null for the following: var result = bindingContext.ModelName);

A: 

The ModelBindingContext object is created and populated by whoever calls into the BindModel() method. If the model is coming in as an argument to your action method, this is done by ControllerActionInvoker.GetParameterValue(), and the ModelName property will be set to the name of the parameter (unless overridden by [Bind(Prefix = ... )]).

If the model is being updated via UpdateModel(), the ModelBindingContext object is created by the UpdateModel() method itself. The ModelName parameter will be the prefix argument passed to UpdateModel().

Levi
when i put this line of code into my custom model binder result is null because model name is null.var result = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);How do I get values out of the valueprovider?Can this be done someother way - basically looking to get the Form or query values out of it. Thanks
Noel