让asp.net mvc的Action支持jQuery直接提交的javascript对象(6)
来源:未知 责任编辑:责任编辑 发表时间:2014-05-26 11:00 点击:次
return array;
}
return null;
}
}
public class ObjectValueProviderResult
: ValueProviderResult
{
private IDictionary<string, ValueProviderResult> _Properties;
public ObjectValueProviderResult(IDictionary<string, ValueProviderResult> properties)
{
_Properties = properties;
base.RawValue = properties.ToDictionary(v => v.Key, v => v.Value.RawValue);
base.AttemptedValue = "{" + string.Join(", ", properties.Select(v => string.Format("{0}: {1}", v.Key, v.Value.AttemptedValue ))) + "}";
}
public override object ConvertTo(Type type, CultureInfo culture)
{
if (!type.IsPrimitive && !type.IsArray)
{
var constructor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance).OrderBy(v => v.GetParameters().Length).FirstOrDefault();
if (constructor != null)
{
var args = constructor.GetParameters()
.Where(v => !v.IsOptional)
.Join(_Properties.DefaultIfEmpty(), v => v.Name, v => v.Key, (l, r) => r.Value).ToArray();
var obj = Activator.CreateInstance(type, args);
foreach( var property in type.GetProperties( BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty ))
{
if (property.GetIndexParameters().Length > 0) continue;
ValueProviderResult propertyValue;
if (_Properties.TryGetValue(property.Name, out propertyValue) && propertyValue != null )
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- .NET简谈互操作(四:基础知识之Dispose非托管内存
- Web Service学习笔记(4)
- Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注
- .net架构的最后思考(箴言)
- JQuery+Asp.net MVC实现用户名重名查询
- 聊聊.net程序设计——浅谈使用VS2010建模拓展(下
- asp.net DataTable和Dataset序列化成Json格式
- 使用ASP.NET MVC3+EF+Jquery制作文字直播系统(四
- MVC3+Entity Framework 实现投票系统(二)
- .NET设计模式:工厂方法模式(Factory Method)[1]



