MVC 项目,在我的 razor View 中,在本地运行,这有效:
<script>
var userLeagueID = '@(ViewBag.userLeagueID)';
var playerRank = '@(ViewBag.playerRank)';
var currentTime = new Date('@(ViewBag.TimeTest)')
//.toUTCString()
;
//var currentTime = new Date();
$(document).ready(function () {
if (typeof currentTime !== 'undefined') {
alert(currentTime);
}
});
</script>
但是,当我发布网站时它不起作用,警告状态为“无效日期”。
我正在从我的服务器代码中获取 @ViewBag.TimeTest,如下所示:
ViewBag.TimeTest = vm.LastPickTime;
(vm.LastPickTime 是一个 c# 日期时间字段。)。我打赌我需要一个在 c# 端运行的函数,但不确定是哪一个,有这么多可供选择?我将尝试一系列不同的功能,看看我是否明白。
请帮我节省时间!
最佳答案
根据 Mat J 的评论,我在 C# 端找到了我需要的方法/函数。
ViewBag.TimeTest = vm.LastPickTime.Value.ToSTring("o");
帮我修好了!非常感谢 Mat 并感谢其他人的其他建议。
关于c# - jquery new Date() 在本地工作但不在线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45987952/