转移.net core 3.1,为.NET 5做准备

This commit is contained in:
ÂëÉñ
2020-10-22 14:59:36 +08:00
parent fd9bca23a7
commit a35d596237
1080 changed files with 175912 additions and 185681 deletions

View File

@@ -1,4 +1,5 @@
using System.Web.Mvc;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Newtonsoft.Json.Linq;
namespace OpenAuth.Mvc.Models
@@ -9,17 +10,30 @@ namespace OpenAuth.Mvc.Models
/// </summary>
public class JobjectModelBinder :IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
public Task BindModelAsync(ModelBindingContext bindingContext)
{
//todo:需要判断前端是否是FormData
var obj = new JObject();
var request = controllerContext.HttpContext.Request;
foreach (var key in request.Form.AllKeys)
{
obj[key] = request.Form[key];
}
return obj;
}
//// Specify a default argument name if none is set by ModelBinderAttribute
//var modelName = bindingContext.BinderModelName;
//if (string.IsNullOrEmpty(modelName))
//{
// modelName = "obj";
//}
//// Try to fetch the value of the argument by name
//var valueProviderResult =
// bindingContext.ValueProvider.GetValue(modelName);
//这个地方会报StringValues的异常好奇怪只能调试源码了
var request = bindingContext.HttpContext.Request;
foreach (var item in request.Form)
{
obj[item.Key] = item.Value[0];
}
bindingContext.Result = ModelBindingResult.Success(obj);
return Task.CompletedTask;
}
}
}