Skip to content
This repository has been archived by the owner on Oct 25, 2019. It is now read-only.

Custom view model binders

Alexanderius edited this page Jan 1, 2019 · 1 revision

To use custom model view binder you should register it using HttpModelHandler.RegisterModelBinder, it will be added to binders pipeline.

public class Startup
{
	public void Configuration(IAppBuilder app)
	{
		...

		HttpModelHandler.RegisterModelBinder<MyModelBinder>();

		app.UseSimplifyWeb();
	}
}

Binder should be deriver from IModelBinder interface.

public class MyModelBinder : IModelBinder
{
	public void Bind<T>(ModelBinderEventArgs<T> args)
	{
		// deserialization logic
	}
}

If you just want to use your binder without default binders, then you should clear binders list first.

public class Startup
{
	public void Configuration(IAppBuilder app)
	{
		...
		HttpModelHandler.ModelBindersTypes.Clear();
		HttpModelHandler.RegisterModelBinder<MyModelBinder>();

		app.UseSimplifyWeb();
	}
}

One example of custom model binder is JsonModelBinder.

<< Previous page Next page >>

Clone this wiki locally