【发布时间】:2020-11-17 19:02:20
【问题描述】:
net core 3.1 mvc 网络应用。在我的服务器上我这样做:
[HttpGet]
public IActionResult LastDate()
{
DateTime send = DateTime.Now;
try
{
send = _db.MySend.ToList().Max(x => x.Date).GetValueOrDefault().AddDays(1);
}
catch { }
return Json( new { date = send });
}
然后在我的前端我做:
var link = 'MYLINK';
var args = {};
$.ajax({
type: "GET",
url: link,
data: args,
dataType: "json",
success: function (data) {
var my_date = data.date;
document.getElementById('Dateee').value = my_date;
},
error: function () {
alert("Error.");
return;
}
});
我尝试将 Json 日期转换为 Javascript,但我无法。感谢您的帮助。
编辑:1. 我正在使用 Microsoft.AspNetCore.Mvc Json。 2. 影响日期的本地化:
var supportedCultures = new[]{
new CultureInfo("cs-CZ")
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("cs-CZ"),
SupportedCultures = supportedCultures,
FallBackToParentCultures = false
});
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("cs-CZ");```
【问题讨论】:
-
请将呈现的响应分享到您的
LastDate操作端点。我们需要知道如何将您的 ASP.NET Core 应用程序配置为序列化DateTime值。你用的是什么 JSON 库? -
您的
Dateee元素的type=""属性值是多少? -
我的 Datee 类型是 date(我已编辑 answear 以获取有关我的 datetime 的更多信息)
标签: javascript json date asp.net-core