mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-20 10:37:55 +08:00
转移.net core 3.1,为.NET 5做准备
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user