1
0

final update

This commit is contained in:
Labality
2021-08-19 16:35:32 +07:00
parent c2e012237f
commit f4fa1d8085
11877 changed files with 1192560 additions and 0 deletions

View File

@ -0,0 +1,28 @@
namespace LOC.Core
{
using System.IO;
using System.Web.Mvc;
using Newtonsoft.Json;
public class JsonModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
if (!IsJsonRequest(controllerContext))
return base.BindModel(controllerContext, bindingContext);
var request = controllerContext.HttpContext.Request;
var stream = request.InputStream;
if (stream.Length == 0)
return null;
stream.Position = 0;
var jsonStringData = new StreamReader(stream).ReadToEnd();
return JsonConvert.DeserializeObject(jsonStringData, bindingContext.ModelType);
}
private static bool IsJsonRequest(ControllerContext controllerContext)
{
var contentType = controllerContext.HttpContext.Request.ContentType;
return contentType.Contains("application/json");
}
}
}