ASP. NET MVC 4 Advanced Programming Learning Notes: Fourth Chapter model

Source: Internet
Author: User

Data model

Data model and O/R conversion, using EntityFramework implementation.

You can use the Firstcode model to define the model first, generate the database through the model, or you can automatically generate the corresponding data model from the database by installing the Efpowertools (accustomed to using this method).

Construction Scaffolding

Construction scaffolding is to provide a template for data maintenance, can automatically complete the data modification and deletion of related basic code, by modifying the underlying code, you can quickly complete the basic data maintenance.

With scaffolding templates, you first need to select a model class in which to select the context class to access the database.

Model binding

In the case of data maintenance, a two-way binding between the form and the data model automatically assigns the properties of the model (implicit model bindings) when committed.

You can also make explicit model binding by calling Updatemodel (album) in the background method, if there is a problem with the binding, and if there is no exception, you can proceed with the following code:

Try

{

Updatemodel (album);

Data manipulation

}

catch (Exception ex)

{

Error handling, re-rendering the view

}

You can also use the following method

TryUpdateModel (album);

if (modelstate.isvalid)

{

Data manipulation

}

Else

{

Error handling, re-rendering the view

}

For data maintenance procedures, it is recommended to use the Ajaxfrom method (see chapter eighth Ajax).

ASP. NET MVC 4 Advanced Programming Learning Notes: Fourth Chapter model

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.