mcintyre321 / AspNetCoreJTokenModelBinder

ASP.NET Core ModelBinder for NewtonSoft JSON.NET JToken

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AspNetCoreJTokenModelBinder

Bind to JToken from form POSTS, following the standard ASP.MVC rules from https://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/

Installation

install-package AspNetCoreJTokenModelBinder


    public class Startup
    {
        ...

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options =>
            {
                options.ModelBinderProviders.Insert(0, new AspNetCoreJTokenModelBinder.JTokenFormModelBinderProvider());
            });
        }
        
        ...
        
    }
    

Usage


    public class HomeController : Controller
    {
        [ValidateAntiForgeryToken]
        public IActionResult FormReciever(JToken content)
        {
            return Content(content.ToString(), "text/html");
        }
        public IActionResult ApplicationJsonReciever(JToken content)
        {
            return Content(content.ToString(), "text/html");
        }

    }
    

About

ASP.NET Core ModelBinder for NewtonSoft JSON.NET JToken

License:MIT License


Languages

Language:C# 95.8%Language:CSS 4.0%Language:JavaScript 0.2%