Skip to content

Instantly share code, notes, and snippets.

@MosheL
MosheL / FormOrJsonModelBinder.cs
Created February 4, 2025 12:53
FormOrJsonModelBinder: allow both JSON and Form (multipart/form-data or url-encoded) POST to a ASP.net core MVC Action.
namespace core.Tools {
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;