The dictionary of parameters has an empty entry for the 'wantedids' parameter, which is of a non-nullable type 'System.Int32', in the 'System.Web.Mvc.JsonResult' method

The console is showing me an error stating that the parameters dictionary contains a null entry for parameter wantedids. I am trying to pass checked boxes to my controller using an array, so only the admin can check all boxes of tips for a specific user. The admin has more than 5 users. Although I am successfully passing the checked elements in my console, it displays an error message saying Internal server error. Can someone help me understand how to update my database with the checked boxes?

<input type="checkbox" class="cktips" idtips="@item.idtips 
checked="@(item.iduser == ViewBag.iduser ? true : false)"/>

.js var wantedids = [];

$("#btnClick").click(function () {
    $(".cktips").each(function () {
     $(this).prop('checked', true);
     ids.push($(this).val());
    });

    $.ajax({
    url: UrlSettingsDocument.Tips,
    data: { ids: ids},
    type: "POST",
    success: function () {
    alert('successs');
    },
    error: function (xhr, ajaxOptions, thrownError) {
    alert(xhr.status);
    alert(thrownError);
   }
 })
})

This is my Controller.cs file

public JsonResult Statics(bool ids,int iduser,int idtips)
{
    try
        {
            if (ids)
            {
                statics = new statics ();
                st.idtips= idtips;
                Database.statics .Add(st);
                Database.SaveChanges();
            }
        else if (!ids)
        {
            var stdelete= Database.statics.Where(a => a.iduser == iduser &&
            a.idtips== idtips).FirstOrDefault();
            Database.statics.Remove(stdelete);
            Database.SaveChanges();
        }
        if (Request.IsAjaxRequest())
        {
            return Json(true, JsonRequestBehavior.AllowGet);
        }
        else
        {
            return Json(true, JsonRequestBehavior.AllowGet);
        }
    }
    catch (Exception ex)
    {
        Logger.Error("Error: {0}", ex.ToString());
        return null;
    }

Answer №1

It appears that the IDs you are looking for may need to be of type bool, but you are submitting an array of values. What data type should the IDs be? Perhaps they should be integers. Try defining it as int[] wantedIds

I'm not entirely convinced that val() is the correct jQuery method to use for a checkbox. Are you trying to retrieve the value from idtips?

Are you including data for the other parameters in your AJAX post data block?

Update:

You are only passing one parameter in the post:

data: { wantedIds: wantedIds},

However, your method includes more than one parameter:

Statics(bool wantedIds, int idUser, int idTips)

Where are the others being set, since they cannot be nullable int?? They must be provided unless they are set as route parameters.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Upon successful registration, users will be automatically redirected to their profile page

Having trouble with the redirection to the login page from my profile page, which is an HTML file and the main page is the login page. I've tried redirecting to both pages, but it always lands in the catch block whenever a redirect is attempted. angu ...

Escaping double quotes in dynamic string content in Javascript can prevent unexpected identifier errors

Need help with binding the login user's name from a portal to a JavaScript variable. The user's name sometimes contains either single or double quotes. I am facing an issue where my JavaScript code is unable to read strings with double quotes. ...

guide on updating JQuery string with JavaScript to incorporate new parameters

Similar Question: How to replace only one parameter or fast with Jquery on Jquery String The website has a query string as follows: http://www.nonloso.html/?nome1=pollo&cognome1=chicken&nome2=a&cognome2=b&nome3=c&cognome3=d This ...

Tips for Transferring Values Between Multiple Dropdown Menus with jQuery

Hello there, can anyone guide me on how to transfer selected items from one multiple combo box to another multi-combo box? I would really appreciate it if someone could provide an example for this scenario. <HTML> <HEAD> <TITLE></T ...

Ajax-powered Autocomplete Functionality

I am looking to include an autocomplete feature for text in my web application. I have the data stored in a SQL server database table and searched Google to find out how to achieve this using autocomplete. Most examples show using a web service, but I am u ...

Postponing the execution of a controller until all JSON files have been fully loaded

I am currently trying to grasp the concepts of AngularJS, so my question might not be perfect. Is it feasible to delay the execution of a controller until the json files are fully loaded in a separate function? Below is the controller code: app ...

Any tips for filtering an array within an array of objects using the filter method?

I have an array of products and models that I am currently filtering based on 'id' and 'category'. var app = angular.module("myApp", []); app.controller("myCtrl", function($scope) { $scope.products = [{ 'id': 1, ...

What is the reason for needing a page reload in Javascript or JQuery?

I'm curious why Javascript or jQuery require a page reload before applying certain effects. CSS updates in real-time, as demonstrated by the following example: This changes dynamically without needing to refresh the page @media all and (max-width:7 ...

Rearranging div placement based on the width of the screen

I am currently working on building a responsive website and I need two divs to switch positions depending on the screen width, both on initial load and when resizing. Despite my efforts in researching and trying various options, I have not been successful ...

C# Troubleshooting: Dealing with Selenium XPath Error

Currently, I am facing a challenge with my HTML page while using Firefox and/or Chrome. I am attempting to determine the correct XPath of the image element that I want to click on the webpage. My coding is in C# and I am using Selenium Automation for this ...

Choosing a row in a table with ASP.NET by utilizing jQuery on click

After setting up a table in ASP.NET with the feature to select individual rows using a link at the end of each row, I have been able to successfully implement it. The process involves setting a value at the top of the view and then dynamically changing the ...

Issue with state change in Component (React with Redux)

I am another person facing a similar issue. I have been unable to identify the error in my code yet. I suspect it has something to do with mutation, but despite trying almost everything, I am at a loss. My component does not update when I add new items to ...

The shadow effects and color overlays do not seem to be functioning properly in Mozilla Firefox

I have designed a popup registration form using the Bootstrap modal class. To ensure form validation, I have integrated some jQuery validation engine functionality. Additionally, I customized the appearance by adding a box shadow, adjusting the background ...

Incorporate a fresh element into an object after its initial creation

Hello, I am looking to create an object in JavaScript that includes an array-object field called "Cities." Within each city entry, there should be information such as the city's name, ID, key, and a District array object containing town data for that ...

PHP - WebCalendar - Show or Hide Field According to Selected Item in Dropdown List

Working with the WebCalendar app found at to make some personalized adjustments to how extra fields function. I've set up two additional fields: one is a dropdown list of counties, and the other is a text field. Within the dropdown list, there is an ...

The initial ajax request may sometimes return as 'undefined' during its first call

I have been working on creating a text input help feature similar to a desktop using the datatable.in table with keyboard navigation. In order to achieve this, I am dynamically changing the data source and also altering the header column. I have been succe ...

Create a placeholder for the module function

Update: Providing more specific details. Our team has developed a Github API wrapper extension and we are looking to test different use cases for it. However, we prefer not to use the API wrapper extension directly during testing and instead want to stub ...

What is the best way to display the next and restart buttons at the bottom of every question?

How can I display the next and restart buttons at the bottom of each question in my JavaScript quiz web app? Why is the user unable to choose the wrong answer from the provided options? I'm facing difficulty showing the next and restart buttons for i ...

Leveraging the useRef hook to adjust the CSS styling of a React component

Currently, I am working on changing the style of a react component by utilizing the useRef hook. So far, I have implemented the useRef hook to reference the specific component whose style I want to modify when clicking on two buttons. Despite my efforts, I ...

What is the method for determining the data type of a column in an Excel sheet that has been

Currently, I am utilizing the XLSX npm library to convert an Excel sheet into JSON format. However, all of the retrieved data is currently being returned as strings. To see a demo of the XLSX read process, you can visit this Stackblitz demo Is there a w ...