这个问题可能是由于jQuery版本的更改导致的,可以通过使用新的jQuery版本来解决这个问题。以下是一个解决办法:
1.在项目中安装最新版本的jquery:
Install-Package jQuery -Version 3.4.1
2.然后在Startup.cs文件中将jQuery添加到RequestLocalizationOptions中:
services.Configure(options =>
{
options.DefaultRequestCulture = new RequestCulture("en-US");
options.SupportedCultures = new[] { new CultureInfo("en-US") };
options.RequestCultureProviders.Insert(0, new JQueryRequestCultureProvider());
});
3.创建一个JQueryRequestCultureProvider:
public class JQueryRequestCultureProvider : RequestCultureProvider
{
private static readonly char[] _cookieSeparator = new[] { '|' };
public override async Task DetermineProviderCultureResult(HttpContext httpContext)
{
if (httpContext == null)
{
throw new ArgumentNullException(nameof(httpContext));
}
string culture = null;
string uiCulture = null;
// One or two cookies with the format c=...
var cookies = httpContext.Request.Cookies;
if (cookies != null)
{
string cookieValue;
if (cookies.TryGetValue(CookieRequestCultureProvider.DefaultCookieName, out cookieValue))
{
var cookieValues = cookieValue.Split(_cookieSeparator, StringSplitOptions.RemoveEmptyEntries);
if (cookieValues.Length == 2)
{
culture = cookieValues[0];
uiCulture = cookieValues[1];
}
}
}
// Query string values override cookies
var qs = httpContext.Request.Query;
if (qs != null)
{
if (!string.IsNullOrWhiteSpace(qs["culture"]))
{
culture = qs["culture"];
}
if (!string.IsNullOrWhiteSpace(qs["ui-culture"]))
{
uiCulture = qs["ui-culture"];
}
}
if (culture == null && uiCulture == null)
{
// Use default culture if it matches a supported culture
string[] testCultures = { "en-US" };
var requestCulture = httpContext.Features.Get();
if (requestCulture != null && requestCulture.RequestCulture != null)
{
foreach (var testCulture in testCultures)
{
if (string.Equals(testCulture, requestCulture.RequestCulture.Culture.Name, StringComparison.OrdinalIgnoreCase))
{
return new ProviderCultureResult(requestCulture.RequestCulture.Culture.Name, requestCulture.RequestCulture.UICulture.Name);
}
}
}