Asp.net MVC development experience 1

Source: Internet
Author: User

Happy Mid-Autumn Festival, ^. In recent days, I have been busy taking some time to write a weekly log. Here are some examples of Experiment verification and some intuitive feelings, so it is inevitable that there is something wrong.

The following are some experiences and experiences on using Asp.net MVC over the past few days.

When to use helper

In fact, the use of helper performance is not too high, can be free, but can be used in the following scenarios

1. url exists

For example, the super connection, form action, and image SRC. Because the developer's urlrouting may change, if the write is dead, the change will be costly.

2. When there is a form and information is modified

Because the <% = viewdata ["field"] %> itself is time-consuming to switch the display, it is better to use HTML to bind the output directly.

3. dropdownlist

Because htmlhelper already provides a good method, you should try to use htmlhelper when filling it.

For insert-type forms, HTML is better.

Notes when using helper

1. Try not to use renderaction

Renderaction is equivalent to executing another action.

Its efficiency is not as good as HTML. renderpartial, and transactions cannot be used. It is uncomfortable in database operations.

However, it is easy to use and can be used when page efficiency is not required.

2. About Microsoft. Web. MVC

In thisProgramThe classes in the set are all expected beta versions, and the performance is not stable, and the possibility of changes is much higher. Therefore, it is best to have a taste, which is not recommended.

Improve Program Performance

In fact, this is a general problem and is the same in any Web architecture.

1. Use transactions whenever possible

Especially when writing data to the database, transactionscope can effectively reduce the number of database connections

2. Database Operations share connection

In my program, ADO is used. netentity, which can be queried through LINQ to entities and cud using my custom database class. It is tested that using the same connection greatly improves the performance of database connection.

This can also be used in LINQ to SQL.

Architecture and Model

In fact, I think the meaning of models is not just the entity, but also the data read/write function.

Encapsulating data read/write into a class is actually a good method to call in a proper controller. I believe many of my friends have already done this.

However, I think it is more appropriate to use the mediator mode to encapsulate data operations, which can link entities and achieve good classification.

 

Here is just a part of my questions. If you agree or disagree, you are welcome to discuss it.

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.