cshtml中的百分比标签

The*_*kal 2 c# asp.net-mvc asp.net-mvc-4

继续使用MVC中的教程,您是否可以在ASPX页面中告诉我替代方法

<div>
    <%=ViewData["CurrentTime"]%>
</div> 
Run Code Online (Sandbox Code Playgroud)

cshtml页面中,VS2013上的MVC 4中的默认视图类型.当我尝试上述内容时,会显示字面含义.即ViewData["CurrentTime"]而不是值DateTime.now

Sat*_*pal 5

当你使用一个cshtml.您正在使用Razor引擎.

在Razor引擎中,你需要使用@

@ViewData["CurrentTime"] 
Run Code Online (Sandbox Code Playgroud)

<%=ViewData["CurrentTime"]%> 是一个ASP.Net引擎代码