fravelgue
fravelgue

Reputation: 2883

Web page (like webmatrix) in mvc3 app

Could i include a single page .cshtml in a MVC3 app (without controller)? I have some static pages but i like to use our base layout.

Upvotes: 0

Views: 69

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039238

Yes, you can. For example include index.cshtml with the following contents in the root of your web site:

@DateTime.Now

and then navigate to /index.cshtml.

Bare in mind that cshtml pages are not allowed in the ~/Views folder so make sure you don't put outside. The Views folder is a special one and is controlled by the ~/Views/web.config in which the base type for Razor views is changed to System.Web.Mvc.WebViewPage because those are MVC views and also they cannot be served directly.

So you could have 2 types of templates:

  • System.Web.WebPages.WebPage (standard WebMatrix WebPage)
  • System.Web.Mvc.WebViewPage (ASP.NET MVC views, stored in the ~/Views folder)

This being said, you cannot use your ~/Views/Shared/_Layout.cshtml with a WebPage. It can only be used with ASP.NET MVC views.

Upvotes: 1

Related Questions