(reprinted) MVC 4.0 Partialview () is it really the same as view ()?

Source: Internet
Author: User

Reprinted from: http://www.cnblogs.com/lori/

When we use razor as the page engine, its view file extension is cshtml or vbshtml, and before as a partial view of the ascx file, after Razor, is also cshtml, which is somewhat different from the non-razor engine, in this respect, The official does not explicitly separate the partial view from the standard view, and sometimes we may have some confusion at the time of development, mainly today, how to use the partial view correctly!

Partial view returns in action be sure to use Partialview () rather than lazy using view (), because if you use view () to render views, the system will think you are a standard view that will add a default master page (Layout) for you. Unless you explicitly set the layout of this property.

Previous Program code:

1 public  ActionResult Partiallogon () 2         {3             return view ();//will recognize its standard view, so add the default Layout4         }

When you return to the view, your partial view will be added to the default master page, which is not what we would like to see, of course, some students do not first bother to add layout=null on the page explicitly

In fact, if you return the partial view correctly, this line certainly does not have to add, hehe.

The correct wording:

1 public  ActionResult Partiallogon () 2         {3             return Partialview ();//The layout of the page is automatically set to Null4         }

How, this time know Partialview () and view () The real difference, hehe!

I think we'll put these two things in a different name after this, Partialview () = render view + without layout

View () = rendering partial views = Auto Plus layout

(reprinted) MVC 4.0 Partialview () is it really the same as view ()?

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.