<%:%> Tag vs @ symbol in MVC project

I'm working on moving a winform program into a webapp format by moving it over to an MVC project. While I'm familiar with the C# language, I'm not familiar with MVC, so I'm walking myself through a couple of tutorials.

I've come to a spot in my tutorial where it instructs me to put

 ViewData["Date"] = DateTime.Now.ToString(); 

in my controller and then put

 The date is <%: ViewData["Date"] %> 

in the corresponding view. When I do this and debug, it doesn't convert to a datetime, but shows the code on a page (happens with a simple string as well)

However, if I change it to

 The date is @ViewData["Date"] 

it works as expected

My questions are:

Why doesnt the <%:%> tag work correctly here, why does the @ symbol do what the <%:%> should, and what is the intended use of each of these.

I'm working in VS2103 (I do have 2015 available, if that makes a difference – generally work in 15 but test in 13 to keep everything separate) .NET 4.5, debugging in IE11

Also, is there a way that anyone knows to put symbols into google and not be ignored? It seems that typing 'C# @ symbol' returns searches for C# symbol…it's strange

by Pidgey_OP via /r/csharp

Leave a Reply