[英]Rendering returned value from JS function in Razor
I have a page on my site that displays a list of members.我的网站上有一个显示成员列表的页面。 I'm using .NET Core MVC and Razor to render my views.
我正在使用 .NET Core MVC 和 Razor 来呈现我的视图。
I'm storing the members' registration date as UTC, and would like that date/time converted to the user's local timezone when they view the page.我将成员的注册日期存储为 UTC,并希望在他们查看页面时将该日期/时间转换为用户的本地时区。
I'm using javascript to do this:我正在使用 javascript 来执行此操作:
<script>
function GetLocalDateTime(utcDate) {
var localDate = new Date(utcDate);
console.log(localDate.toString());
return localDate.toString();
}
</script>
....
@foreach (var member in Model.Items)
{
<tr>
...
<td>
<script>
GetLocalDateTime('@(member.CreatedDate.ToString("MM/dd/yyyy hh:mm:ss tt UTC"))');
</script>
</td>
</tr>
}
The problem is that the return value from the javascript function doesn't get displayed in my table.问题是 javascript 函数的返回值没有显示在我的表中。 But the function is being called, the converted date values are logging in the console.
但是正在调用该函数,转换后的日期值正在控制台中记录。
What am I doing wrong here?我在这里做错了什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.