The presence of viewing models depends on the repository - this is an anti-template. Do not do that.
If you still insist, here is an example of what the model binding would look like. The idea is to have a custom CreateModel where you override the CreateModel method:
public class CustomViewModelBinder : DefaultModelBinder { private readonly IKernel _kernel; public CustomViewModelBinder(IKernel kernel) { _kernel = kernel; } protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) { return _kernel.Get(modelType); } }
which you could register for any viewing model, you need to have this injection:
ModelBinders.Binders.Add(typeof(CustomViewModel), new CustomViewModelBinder(kernel));
source share