/Files/z2002m/dynamicmappingspike.zip
The above example obtains the model from the database. However, the field name in the database must be consistent with the attribute name.
You can obtain the model from the webpage control, which is similar to the reflection code above. You only need to get getfileldinfo.
Assign another value...
Code
Public static class henqpost <t> where T: New ()
{
/** // <Summary>
/// Assign a value to the model
/// </Summary>
/// <Typeparam name = "T"> Model </typeparam>
/// <Param name = "T"> Model </param>
/// <Param name = "form"> request </param>
/// <Returns> </returns>
Public static int getpost <t> (ref t, namevaluecollection form)
{
Int Va = 0;
Type type = T. GetType (); // obtain the type
Propertyinfo [] Pi = type. getproperties (); // gets the property set
Foreach (propertyinfo P in PI)
{
If (Form [P. Name]! = NULL)
{
Try
{
P. setvalue (T, convert. changetype (Form [p. name], p. propertytype), null); // assign a value to the attribute, and convert the type of the key value to the type of the attribute
Va ++; // The number of successfully Assigned attributes.
}
Catch
{
}
}
}
Return Va;
}
}
It can be used in use.
News news = new news ();
Henqpost <News>. getpost (ref news, request. form );