Martin Overgaard
Martin Overgaard

Reputation: 355

I cannot add a partial view in vs2010

When I try to add a partial view using asp.net mvc 3 and razor it just add's a normal .cshtml file and not a partial view. has anyone had this problem before?

/Martin

Upvotes: 1

Views: 605

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

In Razor there is no notion of partial views as there was in WebForms. You only have templates with the .cshtml extension. Depending on how the controller action serves this view (with either return View() or return PartialView()) the _Layout.cshtml will be applied or not. Also if you render a template with either the Html.Partial helper this template will be considered as a partial view. Finally you have the possibility to set whether you want or not a Layout from inside the template itself. For example to disable it:

@{
    Layout = null;
}

So basically in Razor you have templates and you could consider partial views as templates without a layout.

Upvotes: 3

Related Questions