Home kellton

Main navigation

  • Services
    • Digital Business Services
      • AI & ML
        • Utilitarian AI
        • Predictive Analytics
        • Generative AI
        • Machine Learning
        • Data Science
        • RPA
      • Digital Experience
        • Product Strategy & Consulting
        • Product Design
        • Product Management
      • Product Engineering
        • Digital Application Development
        • Mobile Engineering
        • IoT & Wearables Solutions
        • Quality Engineering
      • Data & Analytics
        • Data Consulting
        • Data Engineering
        • Data Migration & Modernization
        • Analytics Services
        • Integration & API
      • Cloud Engineering
        • Cloud Consulting
        • Cloud Migration
        • Cloud Managed Services
        • DevSecOps
      • NextGen Services
        • Blockchain
        • Web3
        • Metaverse
        • Digital Signage Solutions
    • SAP
      • SAP Services
        • S/4HANA Implementations
        • SAP AMS Support
        • SAP Automation
        • SAP Security & GRC
        • SAP Value Added Solutions
        • Other SAP Implementations
      • View All Services
  • Platforms & Products
    • Audit.io
    • AiQ
    • Tasks.io
    • Optima
    • tHRive
    • Kellton4Health
    • Kellton4Commerce
    • KLGAME
    • Our Data Accelerators
      • Digital DataTwin
      • SmartScope
      • DataLift
      • SchemaLift
      • Reconcile360
    • View All Products
  • Industries
    • Fintech, Banking, Financial Services & Insurance
    • Retail, E-Commerce & Distribution
    • Pharma, Healthcare & Life Sciences
    • Non-Profit, Government & Education
    • Travel, Logistics & Hospitality
    • HiTech, SaaS, ISV & Communications
    • Manufacturing
    • Oil,Gas & Mining
    • Energy & Utilities
    • View All Industries
  • Our Partners
  • Insights
    • Blogs
    • Brochures
    • Success Stories
    • News / Announcements
    • Webinars
    • White Papers
  • Careers
    • Life At Kellton
    • Jobs
  • About
    • About Us
    • Our Leadership
    • Testimonials
    • Analyst Recognitions
    • Investors
    • Corporate Sustainability
    • Privacy-Policy
    • Contact Us
    • Our Delivery Centers
      • India Delivery Center
      • Europe Delivery Center
Search
  1. Home
  2. All Insights
  3. Blogs

How to submit a large number of Form-values in ASP.NET Core?

Product Engineering
November 16 , 2017
Posted By:
Kellton
linkedin
How to Submit a Large Number of Form-values in ASP.NET Core

Other recent blogs

enterprises ride the AI wave in 2025
Should enterprises ride the AI wave in 2025 — or risk falling behind?
June 13 , 2025
Testing AI applications and ML models
Testing AI applications and ML models: Revealing proven quality assurance strategies and techniques
June 11 , 2025
AI Agents vs Agentic AI
AI Agents vs Agentic AI: Essential insights every CTO must know
June 10 , 2025

Let's talk

Reach out, we'd love to hear from you!

Image CAPTCHA
Enter the characters shown in the image.
Get new captcha!

HTML forms use either GET or POST method to submit form values to the server. The default method that most of the developers use is GET. When using the GET method, the form data is encoded in the URI as a query string. However, when using the POST method, the form data is placed in the request body.

If you wish to submit a form with a large number of elements (say 500 checkboxes) to our controller post method, then we get a runtime exception: InvalidDataException: Form value count limit 1024 exceeded. This exception means that ASP.NET Core does not allow us to post data which have value and key length above 1024. In order for the developer to explicitly enable this, we can use the following two ways:

  1. Application Level Changes:  Add the code in the startup.cs file as it will apply by default to all controller methods in the application.

    public void ConfigureServices(IServiceCollection services)
    { 
    services.Configure<FormOptions>(x => x.ValueCountLimit = 10000);
    services.AddMvc();
    }
  2. Method Level Changes: To increase the form size limit at the method level, we need to create a custom attribute say “RequestFormSizeLimitAttribute” in the controller post method.

  public class RequestFormSizeLimitAttribute : Attribute, IAuthorizationFilter,    

       IOrderedFilter

    {

        private readonly FormOptions _formOptions;

        public RequestFormSizeLimitAttribute(int valueCountLimit)

        {

            _formOptions = new FormOptions()

            {

                ValueCountLimit = valueCountLimit

            };

        }

        public int Order { get; set; }

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

            }

        }

   }

Once the attribute is ready, we need to increase the key length which can be done in the following two ways:

  1. If no “Antiforgery” token is applied to the controller method, then the attribute can be applied directly on the method without specifying “order” of execution.

    [HttpPost]
    [RequestFormSizeLimit(valueCountLimit: 20000)]
    public IActionResult ActionSpecificLimits(YourModel model)
     
  2. If “Antiforgery” token is applied to the controller method, then we need to specify the order in which the attributes will be executed. If the order is not mentioned then the following exception is raised: “InvalidDataException: Form value count limit 1024 exceeded.”

It is mandatory to execute the “RequestFormSizeLimitAttribute” attribute before the “Antiforgery” token validation filter so that the limits are honored when the antiforgery validation filter tries to read the form. The form size limits only apply to this action.

[HttpPost]
[RequestFormSizeLimit(valueCountLimit: 20000, Order = 1)]
[ValidateAntiForgeryToken(Order = 2)]
public IActionResult ActionSpecificLimits(YourModel model)

LearnMore.jpg

Digital Transformation comprises the largest portfolio of work for Kellton Tech. Learn more about how our digital expertise is increasing ROI of clients looking for.NET Development Services.

Want to know more?

Testing AI applications and ML models
Blog
Testing AI applications and ML models: Revealing proven quality assurance strategies and techniques
June 11 , 2025
B2B ecommerce trends
Blog
Top Ecommerce Trends 2025: Stay Ahead in the Digital Market
June 05 , 2025
automated software testing services
Blog
Why Automated Testing is enterprise’s strategic quality assurance edge in 2025
June 04 , 2025

North America: +1.844.469.8900

Asia: +91.124.469.8900

Europe: +44.203.807.6911

Email: ask@kellton.com

Footer menu right

  • Services
  • Platforms & Products
  • Industries
  • Insights

Footer Menu Left

  • About
  • News
  • Careers
  • Contact
LinkedIn LinkedIn twitter Twitter Youtube Youtube
Recognized as a leader in Zinnov Zones Digital Engineering and ER&D services
Kellton: 'Product Challenger' in 2023 ISG Provider Lens™ SAP Ecosystem
Recognized as a 'Challenger' in Avasant's SAP S/4HANA services
Footer bottom row seperator

© 2025 Kellton