-
Notifications
You must be signed in to change notification settings - Fork 0
Modelbinding
Unlike Routing, Modelbinding is not shared between Webforms and Mvc. For Mvc, you can find all the classes and interfaces in the System.Web.Mvc namespace and for Webforms they live in System.Web.Modelbinding. At first glance they look and operate the same, but they are two completly separate implementations.
ExitStrategy provides all the plumbing to share the validation of your models between the two worlds. You can have a Razor view with inline validation on a Webforms page where a ValidationSummary Control uses the same data to provide a summary. You can try this on our demo site.
Both namespaces contain an IModelBinder interface (Webforms|Mvc). Their signature differ and they need to be registered in diffrent ways:
System.Web.Mvc.ModelBinders.Binders.Add(typeof(DateTime), new MvcDateTimeModelBinder());
System.Web.ModelBinding.ModelBinderProviders.Providers.RegisterBinderForType(typeof(DateTime), new WebformsDateTimeModelBinder());ExitStrategy will help you bridge the two parallel implementations. There is a IModelBinder interface that combines the two. Classes that implement this interface can be registered to Webforms and Mvc using the ModelBinderAdapter:
ModelBinderAdapter.AddModelBinder(typeof(DateTime), new SharedDateTimeModelBinder());