Advantages and disadvantages of the branch view of Asp.net mvc3

Source: Internet
Author: User

When talking about the Division view, I believe everyone will think of the corresponding ascx division control in the web form era. We can control the Division view more easily in the Mvc era.

To describe the Division view, let's first discuss the advantages of the Division View:

  1. The Division view enables system ins. I highly recommend that you do not include anything that can be separated. Because every functional module is independent, we can reuse it elsewhere.
  2. The Division view also brings about the advantages of division of labor and cooperation. Now is an era of cooperation. No one can complete the prescribed tasks without cooperating with others, unless it is a good man. The Division view can bring us the division of labor and cooperation in different development modules.
  3. The branch view also has the advantages of the Mvc era, that is, its implementation is simple. Since I learned how to use Mvc, I basically seldom write web form code, because I don't feel as fluent as Mvc. Html. partial (partialName) displays a page of the segment view.


This article briefly describes the advantages. Since we can find the advantages, we want to better use them in actual projects. After all, programmers are pursuing laziness and a piece of code, three sentences can be done, and we will never write three and a half sentences. Of course, the minimization principle is also the ultimate goal of code optimization.

So what functions can be implemented in Mvc? And what do we need to pay attention?

  • Html. Partial (partialName) and html. RenderPartial (partialName) are the first choice. In fact, we can specify any. cshtml file in these two methods, not necessarily just minutes.

    Department view. Let's recall the difference between the branch view and view? That is, the view has the head and body labels. You can define js and specify the parent page. However, right-click Vs to add

    In the segment view, we can see that there are only some basic html tags without any head or body, but this does not mean that we cannot add them, so partialName can be any

    View File. However, we 'd better create a branch view, because we finally want to combine these Branch views into a page. If only the html tag of the branch view is used

    The html tags on the page are very clean.

    In addition, do not define or reference css and js in the segment view. If you need to define or reference the entire page. The reason is that is the part View File and the overall page.

    The path may not be in the same directory, so css or js files cannot be found. 2. It is harmful to the html code of the entire page.

  • The html. Action and html. RenderAction () methods can also be used as Part views.

I don't need to elaborate on the specific usage. Everyone is familiar with htmlHelper, because it is commonly used.

During this time, I was working on a project and used the branch view a lot. Now I want to summarize it, so that later learners will not take a detour.

  1. If you can, try to use the dashboard page, so that you can control the style of the website.
  2. Use a separate css file and a separate js file. Try not to define the style in the segment view, but on the overall page.
  3. There should be as few html tags as possible in the segment view. There should be no impurity in addition to the content to be displayed. Add style css and js on the overall page.
  4. If possible, try to use html. partial (partialName) or html. renderPartial (partialName) instead of html. action as the Division view, because this method will interact with the Controller.
  5. Try to use the Model method to pass the value of the segment view. If two parameters need to be passed in a segment view, we recommend that you divide the view into two segments.
  6. Using the segment view makes it difficult to adjust the overall page style. Therefore, we recommend that you first make the page as a whole and then divide it into different segment views.
  7. Too many Branch views increase server latency. Therefore, we recommend that you control the branch view properly within 10. If the server permits it, you can do more.
  8. Pay attention to the name of the tag id in the Division view. It is best to use a fixed naming method to minimize conflicts. After all, tags with the same name may cause potential risks to the program.

I believe that, every day, you will have a better future.

Related Article

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.