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 ()?