ASP. NET MVC TryUpdateModel Update model

Source: Internet
Author: User

Summary reference: Original address http://www.it165.net/pro/html/201305/5724.html

TryUpdateModel (model) By default matches the field in the form form on the View page with the Model field.

If the same, the values in the form are updated to the model,

If you want to update only a few fields, you can call its overloaded function

For example

  

New string " Field 1 " " Field 2 " " Field 3 " })

But if we have more than 10 20 fields on our page today, it might take a lot of time to use the above method to close the name of a field!
At this point we can use FormCollection to receive data from the View to do field updates, so you can change to the following wording:

  

TryUpdateModel (model, Fromvalue.allkeys) && modelstate.isvalid)

You can also exclude formcollection to receive certain fields from View data

"" New string "Field 1 " })

This allows you to exclude "field 1"

ASP. NET MVC TryUpdateModel Update 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.