Last post Jan 03, 2014 09:07 AM by Incongruous
Jan 02, 2014 05:39 AM|Incongruous|LINK
Following the example in
hereI added this code in my HomePage:
<div style="text-align: center;">
<p>The time is @DateTime.Now.ToString()</p>
Two things I noticed here: 1) IE 11.0.96.... does not display the line at all and 2) Safari 5.1.7 display the line as: "The time is @DateTime.Now.ToString()". That is, it does not recognize the .Net (C#) command. I am using my newly installed Webmatrix
to edit the C:\HomePage\index.html. What am I doing wrong?!
Thanks in advance
Jan 02, 2014 05:53 AM|PatriceSc|LINK
As this file uses a ".html" extension, it is NOT processed at all on the server and is rendered "as is" (so the Safari behavior is expected. It show also show in IE11, try perhaps "view source").
You likely have an option in web matrix to add a .cshtml page. This page will be then processed server side before being rendered to the browser and should produce the result you expect.
Edit; the basic idea is that the only thing that a browser understand is HTML. So when the browser ask a document to a web server:
- either this is already an HTML document and the server sends back this unchanged to the browser (this is what happens currently as this is a .html file)
- or it uses some kind of server side technology and it then "executes" on the server to provide the final HTML markup which is then sent to the browser (this is what you'll have if you turn this into a .cshtml file)
Jan 02, 2014 05:58 AM|chandrashekar|LINK
As PatriceSc mention first what you have written is razor syntax that would work with the .cshtml extension and you have created .html that is why the it did not worked.
Try to use .cshtml with webmatrix.
Read about the syntax of the razor with C#.
Jan 03, 2014 09:07 AM|Incongruous|LINK
Hey! thanks a lot for the all the help. I did as you suggested, and even though I have not finished reading all the tutorials in the link you, kids, provided me with, I went ahead and renamed my index.html to index.cshtml. After
renaming it, I viewed the web page in IE11 and had no problem, but Safari would not even show the page. I have not done any research on that, but just thought I should give you a feed back.
Have a grate date and thanks again for the help.