Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Views to Partial Views

I created some views in visual studio by clicking right click=> add => view. I select in the selection: "use a layout or master page". Now I want to turn these views to partial views should I delete it and create new? or I can somehow turning it to partial view without deleting the views?

like image 797
ilay zeidman Avatar asked Jan 20 '14 12:01

ilay zeidman


People also ask

How do you pass view data to partial view?

Pass Data to Partial View using ViewBag/ViewData You can use ViewData / ViewBag to pass the information from the controller's action method to the View. ViewData uses ViewDataDictionary and ViewBag is just a wrapper around ViewData using dynamic feature.

Can we use view as partial view?

To create a partial view, right-click on view -> shared folder and select Add -> View option. In this way we can add a partial view. It is not mandatory to create a partial view in a shared folder but a partial view is mostly used as a reusable component, it is a good practice to put it in the "shared" folder.

What is the difference between view and partial view?

Views are the general result of a page that results in a display. It's the highest level container except the masterpage. While a partial view is for a small piece of content that may be reused on different pages, or multiple times in a page.


1 Answers

In Razor there is no much difference in View and partial view Only difference is

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

If there is no layout specified they could be considered as partial views.

From your controller action you return PartialView(); instead of return View(); this layout will not be applied.

like image 182
Nilesh Gajare Avatar answered Oct 07 '22 08:10

Nilesh Gajare