Maybe it will dup , but I didn’t found anything that will help me to fix the problem.
I have Controller that can Have different ViewModels :
I would like to do something like:
[HttpPost]
public ActionResult ExportToExcell(ILeadsViewModel model)
{
}
My ViewModels are:
public class ViewModelTest1 : ILeadsViewModel
public class ViewModelTest2 : ILeadsViewModel
public class ViewModelTest3 : ILeadsViewModel
Is there any chance to configure Unity return right instance for my ViewModel ?
If possible how ?
If possible , but you dont suggesting to this , please explain why.
Thanks.
You could write a custom model binder for the
ILeadsViewModeltype that will return the proper view model based on some request properties. Here’san exampleof a custom model binder. In this example I have used a Type property present in the request toActivator.CreateInstancethe concrete view model but you could use Unity or whatever. But bear in mind that you should have some information present in the request that would allow the model binder to know which concrete instance of the view model to return.