AJAX request failing with 431 status code

Viewed 31

I have an MVC application with the following model:

public class OnlineEnrollment_Indicative_Verify
{
    public string fldData_DeferralPorD { get; set; }
    public string fldData_BirthDate { get; set; }
    public string fldData_EmploymentDate { get; set; }
    public string fldData_Email { get; set; }
    public string fldData_PhoneNumberHome { get; set; }
    public string fldData_PhoneNumberWork { get; set; }
    public string fldData_PhoneNumberWorkExt { get; set; }
    public string fldData_CarrierRoute { get; set; }
    public string fldData_Default_Percent { get; set; }
    public string ss_LastName { get; set; }
    public string ss_FirstName { get; set; }
    public string ss_AddressLine1 { get; set; }
    public string ss_AddressLine2 { get; set; }
    public string ss_AddressCity { get; set; }
    public string ss_AddressState { get; set; }
    public string ss_AddressZip { get; set; }
    public string ss_CtrbKMaxPct { get; set; }
    public string ss_CtrbKMinPct { get; set; }
    public int ss_LoanFund { get; set; }

    public string messageLiteral { get; set; }
    public int electedRate { get; set; }
    public string outputMaxPct { get; set; }
    public string outputMinPct { get; set; }

    public string currentPage { get; set; }

    public List<ParticipantData_INV_Class> electionData { get; set; }
    //public List<FundElection> fundElections { get; set; }

}

If you notice, the definition of the variable fundElections is commented out.

I have a second model that looks like this:

public class FundElection
{
    public int percent { get; set; }
    public int fund { get; set; }
    public string fundName { get; set; }
}

I have a view where I use jQuery to send an Ajax request to my controller. The code in the controller looks like this:

    [HttpPost]
    public string Summary(List<FundElection> formData)
    {
        var returnString = "";

        TempData.Keep("OnlineEnrollmentSessionData");
        OnlineEnrollment_Indicative_Verify newModel = JsonConvert.DeserializeObject<OnlineEnrollment_Indicative_Verify>((string)TempData["OnlineEnrollmentSessionData"]);

        TempData["OnlineEnrollmentSessionData"] = JsonConvert.SerializeObject(newModel);

        return returnString;
    }

When I run the application, the ajax executes and sends data to the controller. When I have a breakpoint set in the Summary, I can view the contents of the formData and everything looks correct.

Now, I want to take formData (the data that is passed by Ajax from the view to the controller) and store the information in the newModel variable. The newModel variable is of type OnlineEnrollment_Indicative_Verify. So I uncomment the fundElections declaration and make no other changes to any code in the application. I run the application again. Now I get a 431 (Request Header Fields Too Large) error in the console.

Any ideas why this might be happening?

EDIT 1: This is the code of the ajax call that is in the view:

        var sendData = [];
        var fundName = "";
        var percent = 0;
        var fund = 0;
        var data = {};

        $('.election').each(function () {
            percent = parseInt($(this).val());
            if (percent > 0) {
                fund = $(this).next().val();
                fundName = $(this).parent().prev().text();
                console.log("fundName = " + fundName);
                data = {
                    'fund': fund,
                    'fundName': fundName,
                    'percent': percent
                };
                sendData.push(data);
            }

        });
        $.ajax({
            type: "POST",
            url: "@Url.Action("Summary")",
            dataType: "text",
            data: { 'formData': sendData },
            success: function (msg) {
                $("form").attr('action', '/OnlineEnrollment/Summary');
                $("form").submit();
            },
            error: function (req, status, error) {
                console.log("ajax fail: " + msg);
            }
        });

And the data that is being passed by the ajax looks like this:

 {'fund':37, 'fundName':'temp fund name', 'percent': 100}

Any assistance is greatly appreciated.

0 Answers
Related