Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor views vs partial views

how does visual studio determine which is a view vs a partial view? Another question would be; is there a way to convert my views into partial views?

like image 774
frank Avatar asked Jul 21 '11 21:07

frank


1 Answers

In Razor there is no distinction between views and partial views as there is in WebForms (.aspx vs .ascx). In Razor all views are templates. Those templates could have a Layout:

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

In this case they are views. If there is no layout specified they could be considered as partial views. The Layout is usually defined in the ~/Views/_ViewStart.cshtml file.

This being said if from your controller action you return PartialView(); instead of return View(); this layout will not be applied.

I would recommend you reading the following blog post about Razor views and layouts.

like image 84
Darin Dimitrov Avatar answered Nov 12 '22 14:11

Darin Dimitrov