Link to home
Start Free TrialLog in
Avatar of HLRosenberger
HLRosenbergerFlag for United States of America

asked on

Help with C#, MVC, razor.

I'm a VB.NET/WEB forms guy learning C# and MVC.  I created a simple project following an online video.  I'm stuck on the code below.  I set ViewData in the controller C# code.\, and now I want to show it in the view.   In the video, I can see that syntax-wise it highlights the <%  %> characters and at run time displays the correct data.   But in my project, I get no such highlighting and the literal data shown below is displayed.  What am I doing wrong?    

Time is <% = ViewData["time"]%>
ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HLRosenberger

ASKER

I'm new to this.  Don't know if it's razor.  I just followed the video, and the guy used that syntax in the cshtml file inside a div tag.
You are correct. Below code worked.   Now the question is why the different syntax, and how/why it work in the video I watched.  Maybe a different version of MVC?  different version of Razor? etc...

<div>
        Time is @ViewData["time"]  
</div>
SOLUTION
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Razor was introduced as the view engine starting with MVC 3.   Perhaps the video is using older than MVC 3.

MVC 4 is the current version if you're using .NET 4
MVC 5 is the current version if you're using .NET 4.5
Thanks!