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);
                    }
                }
            }

相关内容

热门资讯

重大来袭!爱来掌中宝有没有挂(... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...
新手必备!心悦透视辅助器免费(... 新手必备!心悦透视辅助器免费(透视)wepoker游戏安装教程(wpk教程确实有挂)这是一款可以让一...
一起来探讨!新道游辅助器透视挂... 一起来探讨!新道游辅助器透视挂(透视)pokemmo脚本最新版(存在挂教程有挂教程);无需打开直接搜...
透视模拟器!好玩贰柒拾辅助(透... 透视模拟器!好玩贰柒拾辅助(透视)werplan透视挂(AI教程有挂讲解);无需打开直接搜索薇:13...
玩家必知教程!新道游辅助器免费... 哈糖大菠萝可以开挂吗是一款专注玩家量身打造的游戏记牌类型软件,在哈糖大菠萝可以开挂吗这款游戏中我们可...
如何分辨真伪!凑一桌关春天怎么... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...
记者发布!途游辅助器(透视)w... 记者发布!途游辅助器(透视)wpk辅助哪里买(技巧教程证实有挂) 了解更多开挂安装加(1367043...
重磅来袭!四川皮皮辅助(透视)... 重磅来袭!四川皮皮辅助(透视)佛手在线大菠萝为什么都输(存在挂教程了解有挂);无需打开直接搜索微信(...
透视好友!小南娱乐科技(透视)... 大家好,今天小编来为大家解答小南娱乐科技这个问题咨询软件客服可以免费测试直接加微信(13670430...
总算了解!新久久辅助器(透视)... 新久久辅助器 无需打开直接搜索微信:136704302本司针对手游进行,选择我们的四大理由: 1、软...