asp.net 实体类赋值

View Code
private const string ScriptSetFunction = "(function(o,v){o=document.getElementById(o)||document.getElementsByName(o)[0];if(o)o.value=v;return arguments.callee;})";

public static void SetHtmlPost(Page page, object entity)
{
StringBuilder script
= new StringBuilder(ScriptSetFunction);
foreach (PropertyAccess property in EntityUtility.GetEnumerable(entity))
{
object value = property.GetValue(entity);
if (value != null)
{
script.AppendFormat(
"('{0}','{1}')", property.MappedName, value);
}
}
page.ClientScript.RegisterStartupScript(page.GetType(),
string.Empty, script.Append(";").ToString(), true);
}

public static void GetHtmlPost(Page page, object entity)
{
foreach (PropertyAccess property in EntityUtility.GetEnumerable(entity))
{
string value = page.Request.Form[property.MappedName];
if (value != null)
{
property.SetValue(entity, property.ChangeType(value));
}
}
}
原文地址:https://www.cnblogs.com/Googler/p/2006352.html