Robert S
Robert S

Reputation: 496

Why Does Razor CSHTML Code Display as Plain Text?

My organization is contemplating a move to .NET Razor. I am trying to learn it; and to do so I would like to write test scripts; however, after I copied some code into a CSHTML file and navigated to the URL, the Razor code is displayed on the page.

The code below is what I am testing.

<!doctype html>
<html>
<body>
    Hello, @Request["name"]
</body>
</html>

When viewed in the browser (ex: http://mysite/test.cshtml?name=Bob) we see:

Hello, @Request["name"] instead of Hello, Rob

My teammates verified:

Our server is IIS 7.5 running on Windows 2008 R2.

Upvotes: 0

Views: 1018

Answers (3)

Jimesh
Jimesh

Reputation: 529

I faced the same issue.

Check whether you are using any key in the controller which is not defined or is commented in the Web.config.

My issue is resolved. I was using a key with the help of ConfigurationManager.AppSettings in my controller. But it was not present in the Web.config. As soon as I added it in my Web.config it all started working fine.

Upvotes: 1

Daniel Lavoie
Daniel Lavoie

Reputation: 109

Did you activated the *.cshtml extension and linked it to the application pool?

Upvotes: 0

Radoo.ir
Radoo.ir

Reputation: 1

You should build a Razor Web Pages site in visual studio by going to File » New » Web Site. You can get more information about ASP.NET Web Pages from here: http://www.asp.net/web-pages. It is the recommended starting point for people who are new to ASP.NET development

Upvotes: 0

Related Questions