ASP.NETCore中,如果将表单输入设置为空字符串,则asp-for字段与输入文本字段不同步。
创始人
2024-09-18 17:00:47
0

这个问题可能是由于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);
                    }
                }
            }

相关内容

热门资讯

9分钟攻略!aapoker钻石... 9分钟攻略!aapoker钻石代理有挂的(透视)辅助透视((2022已更新))(哔哩哔哩)1、每一步...
透视实锤!wpk ai辅助!果... 透视实锤!wpk ai辅助!果真是真的有挂((2023已更新))(哔哩哔哩)是一款可以让一直输的玩家...
必备辅助推荐!雀神秘籍app(... 必备辅助推荐!雀神秘籍app(辅助挂)果真真的有挂(真实有挂)-哔哩哔哩1、点击下载安装,微信小程序...
透明私人局!广东老友麻将神器(... 透明私人局!广东老友麻将神器(辅助挂)其实是真的有挂(有挂工具)-哔哩哔哩1、这是跨平台的广东老友麻...
5分钟攻略!微扑克ai辅助工具... 您好,微扑克ai这款游戏可以开挂的,确实是有挂的,需要了解加微【439369440】很多玩家在这款游...
透明讲解!cloudpoker... 透明讲解!cloudpoker有辅助透视么!的确是真的有挂((2021已更新))(哔哩哔哩),亲,有...
终于清楚!广东雀神免费智能辅助... 终于清楚!广东雀神免费智能辅助(辅助挂)原来真的有挂(有挂秘笈)-哔哩哔哩;科技详细教程小薇《757...
技术分享!四方河南麻将脚本(辅... 技术分享!四方河南麻将脚本(辅助挂)确实真的有挂(存在有挂)-哔哩哔哩准备好在四方河南麻将脚本ia的...
8分钟了解!wepoke打伙牌... 8分钟了解!wepoke打伙牌(透视)辅助透视((2023已更新))(哔哩哔哩)是一款可以让一直输的...
三分钟了解!微扑克智能ai辅助... 微扑克智能透视辅助版本解析‌,三分钟了解!微扑克智能ai辅助!的确真的有挂((2022已更新))(哔...