Idrees
Idrees

Reputation: 833

MVC3 Razor View Engine: How can I add view file extension other than (cshtml)?

I want to add file extension to razor view engine other than cshtml. Any clue you guys?

Upvotes: 0

Views: 1562

Answers (3)

crimbo
crimbo

Reputation: 11211

You can use *.cshtml view files to return other file types in the web app (they don't have to contain html). For example, you can use attribute-based routing to return a URL with any file extension (info here: ASP.NET MVC path with file extension), and within the *.cshtml you can set the content-type, eg:

@{
   Response.ContentType = "text/plain";
}    

The main disadvantage of doing is this is that your VisualStudio intellisense will be mucked up for the markup portion of the file - but other than that it works pretty well.

Upvotes: 0

Idrees
Idrees

Reputation: 833

I've made a MVC service that generates CSS files based on configuration files.

I'm returning the CSS file using the Razor view. Simply the view has CSS syntax and placeholders. The place holders are replaced with values from the passed model.

I wanted the razor view engine to view .css file besides .cshtml, just for the sake of intellisense support in the visual studio.

I believe the solution to this problem starts here

Upvotes: 1

Adam Tuliper
Adam Tuliper

Reputation: 30152

Since you are looking at your own view type here, use the virtual path provider. http://rebuildall.umbraworks.net/2009/11/17/ASP_NET_MVC_and_virtual_views

Upvotes: 1

Related Questions