绑定到“模型"的集合超过MvcOptions.MaxModelBindingCollectionSize(1024) [英] Collection Bound to 'Model' Exceeded MvcOptions.MaxModelBindingCollectionSize (1024)

查看:83
本文介绍了绑定到“模型"的集合超过MvcOptions.MaxModelBindingCollectionSize(1024)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向控制器提交一个包含1024个以上的项的数组(当前为2500个)时,我遇到了异常.似乎您可以提交的项目数上限为1024.

I'm getting an exception when submitting an array of more than 1024 items to a controller (currently 2,500 items). It seems there is a max limit on the number of items you can submit of 1024.

它似乎是在MvcOptions中设置的,但是我使用的是.Net Core 3.0和端点路由,所以我无法通过UseMVC访问MvcOptions.

It seems to be set in MvcOptions, however I'm using .Net Core 3.0 and using endpoint routing, so I don't have access to MvcOptions through UseMVC.

如何提高此限制?

我之前通过添加helper属性提高了限制,如下所示.但是我不确定在哪里需要设置此特定限制-它似乎不是HttpContext.Features的一部分.

I've raised limits before by adding a helper attribute, as follows. However I'm not sure where I would need to set this particular limit - it doesnt appear to be part of HttpContext.Features.

    public void OnAuthorization(AuthorizationFilterContext context)
    {
        var features = context.HttpContext.Features;
        var formFeature = features.Get<IFormFeature>();
        if (formFeature == null || formFeature.Form == null)
        {
            features.Set<IFormFeature>(new FormFeature(context.HttpContext.Request, _formOptions));
        }
    }

推荐答案

在Startup#ConfigureServices

In Startup#ConfigureServices

services.Configure<FormOptions>(options => options.ValueCountLimit = 5000); // select your max limit

这篇关于绑定到“模型"的集合超过MvcOptions.MaxModelBindingCollectionSize(1024)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆