If you specified Layout property inside your content view there is no difference. When returning View()
, ViewStart.cshtml executed but when returning PartialView()
, ViewStart.cshtml was not executed.So when view does not set Layout property, return View()
can take Layout from Viewstart.cshtml but return PartialView() cannot.For more information Rendering difference between PartialView() and view()
If your content.cshtml contains this code block they are same and generate view wrapped in specified layout.
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
If Content view does not specify any Layout, return View()
gets its Layout property from ViewStart.cshtml and generates a view wrapped in layout. But return PartialView()
only generates the content view because Viewstart.cshtml is not executed when you return PartialView()
.