Basics of Layout, View and Partial View in MVC.

In this post we will focus on basics of View section of Model View Controller (MVC) architectural pattern.



There are three types of Views in MVC.
  1. Layout (Master Page)
  2. View (Page)
  3. Partial View (User Controller)


Layout


Layout is used to provide consistent experience to the user in terms of Header Footer and Menus throughout the Application / Website. We can also defined commonly used Stylesheets and Scripts in layout so many views in the application can refer it mean we don't need to to define those Sylesheets and Scripts on every View in the application. So here it clears to us Layout eliminates the duplication code in the View.


View


View is interface or page though which user can interact with the Application or Website. View displays data from Model/Controller to User.
To know more about redirection of views visit here 


Partial View

And the Partial View is View(mark up file) that renders HTML output within another View. So Partial View is child View and can be used for re-usability purpose in the application.


Microsoft suggest to not use Partial View where complex rendering logic or code execution is required to render the markup, Instead of partial view, use View component.here

Conclusion
We can use Partial View in below cases

  1. When we have large markup and we can break it into smaller markup.
  2. To eliminate the duplication code.
I hope this clears up the basics of Layout, View and Partial View in MVC.

Comments

Popular posts from this blog

Difference Between return View(), return Redirect(), return RedirectToAction() And RedirectToRoute() In MVC.

RenderBody() and RenderPage() in MVC.

Basic Difference Between Convert.ToString() And .ToString() Method In C#