我正在使用JsonDotNetValueProviderFactory,并且在将数据绑定到控制器参数时遇到问题-我在List对象中没有任何数据,请您提供宝贵的输入信息。
基本上我正在使用angular js,这是一个excel文件上传,因为我无法使用这种方法上传大型excel数据
JavaScript代码
testCachedData?.response.url // Ok
testCachedData?.isEmpty // false
testCachedData?.data // contains bytes
在global.asax中
$scope.SaveData = function (excelData) {
var person = getPerson();
//var json = JSON.stringify(person);
var data = $.toJSON(excelData);
$http({
method: "POST",
url: "/Home/ImportData",
dataType: 'json',
//data: JSON.stringify(excelData),
data: { objects: data },
//data: json
headers: {
'Content-Type': 'application/json'
}
}).then(function (data) {
if (data.status) {
$scope.Message = excelData.length + " record inserted";
}
else {
$scope.Message = "Failed";
}
}, function (error) {
$scope.Message = "Error";
})
}
JsonDotNetValueProviderFactory类
ValueProviderFactories.Factories.Add(new JsonDotNetValueProviderFactory());
这是我的动作方法
我没有在这里获取任何数据到对象
public sealed class JsonDotNetValueProviderFactory : ValueProviderFactory
{
public override IValueProvider GetValueProvider(ControllerContext controllerContext)
{
IValueProvider vProvider = null;
if (controllerContext == null)
throw new ArgumentNullException("controllerContext");
if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
return null;
var reader = new StreamReader(controllerContext.HttpContext.Request.InputStream);
var bodyText = reader.ReadToEnd();
//dynamic objects = JsonConvert.DeserializeObject<ExpandoObject>(bodyText, new ExpandoObjectConverter());
//foreach (var obj in objects)
//{
//vProvider = String.IsNullOrEmpty(bodyText) ? null : new DictionaryValueProvider<object>(objects, CultureInfo.CurrentCulture);
//}
return String.IsNullOrEmpty(bodyText) ? null : new DictionaryValueProvider<object>(JsonConvert.DeserializeObject<ExpandoObject>(bodyText, new ExpandoObjectConverter()), CultureInfo.CurrentCulture);
//return vProvider;
}
}