Skip to content

Instantly share code, notes, and snippets.

@stevejgordon
Created November 23, 2016 13:18
Show Gist options
  • Select an option

  • Save stevejgordon/0f54c4dd4fccefd744229b485f253619 to your computer and use it in GitHub Desktop.

Select an option

Save stevejgordon/0f54c4dd4fccefd744229b485f253619 to your computer and use it in GitHub Desktop.
public static class MvcOptionsExtensions
{
public static void UseHtmlEncodeModelBinding(this MvcOptions opts)
{
var binderToFind = opts.ModelBinderProviders.FirstOrDefault(x => x.GetType() == typeof(SimpleTypeModelBinderProvider));
if (binderToFind == null) return;
var index = opts.ModelBinderProviders.IndexOf(binderToFind);
opts.ModelBinderProviders.Insert(index, new HtmlEncodeModelBinderProvider());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment