Obtain the model from the database. Obtain the model from the webpage control.

Source: Internet
Author: User

/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 );

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.