我是my的新手,我试图通过使用Viewdata.But来传递当前的日期和时间--它没有得到我的代码在这里
namespace FirstHelloWorldProjct.Controllers
{
public class HelloWorldController : Controller
{
//
// GET: /HelloWorld/
public ActionResult Index()
{
ViewData["CurrentTime"] = DateTime.Now.ToString();
return View();
}
}
}
我的观点代码在这里
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
This is Hello World...<br/>
The Current Date and time is <%= ViewData["CurrentTime"]%>
</div>
</body>
</html>
输出在这里,This is Hello World... The Current Date and time is <%= ViewData["CurrentTime"]%>
发布于 2017-05-16 21:37:45
我认为在Asp.net MVC中,我们在下面使用Razor语法作为度量。
您需要使用@ViewData["CurrentTime"]
而不是<%= ViewData["CurrentTime"]%>
https://stackoverflow.com/questions/44016325
复制相似问题