What is the best way to verify the accuracy of my model when it includes an array property?

One of the challenges I am facing is dealing with a class that has an array property in MVC.

public class MyClass
{
    public int Contrato_Id { get; set; }
    public string Contrato { get; set; }
    public int Torre_Id { get; set; }
    public string Torre { get; set; }
    public SkillsATB[] Skills { get; set; }
}

Despite my efforts, when I perform a POST request via jQuery ajax, my ModelState validation always returns false.

 if (ModelState.IsValid)
 {
    var _current = _Service.Insert(current);
    return Json(new { result = "success", resultValue = "" });
 }

View debugging image here

Although the property SkillsATB seems to be populated correctly with elements, there might be something missing for that specific array.

function ConvertToSkillsObject(id, name) {
    var skill = {
        Id: Math.round(id),
        Nombre: name,
        Descripcion: "",
        Activo: "1",
        Asignada: 1
    }

    return skill;
}

function GetSkillsAsignados() {
    var asignados = [];

    $("#sortable2").children().each(function () {
        var item = ConvertToSkillsObject($(this).attr("data-id"), $(this).html())
        asignados.push(item);
    });

    return asignados;
}
var MyClass= {        
        Correo: $('#correo').val(),
        CorreoLider: $('#correoLider').val(),
        CorreoLiderBSD: $('#correoLiderBSD').val(),
        FechaNacio: $('#fechaNacio').val(),
        Contrato_Id: $('#contrato_Id').val(),
        Torre_Id: $('#torre_Id').val(),
        Skills: GetSkillsAsignados()
};

$.ajax({
    url: "../../MyController/Save",
    type: "POST",
    data: JSON.stringify(MyClass),
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    success: function (e) {
... //more javascript

Answer №1

Eliminate the attribute from the model prior to validation by executing this command: ModelState.Remove("Skills");

Answer №2

ISSUE RESOLVED

The issue stemmed from an error in the datepicker CSS where the date format was incorrect. This had no connection to any previous issues.

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

Ways to simulate a constant that acts as a dependency for the service being examined?

I'm currently experimenting with a file named connect-key.js. It relies on a dependency called keyvault-emulator. Content of File #1: // connect-key.js file const { save, retrieve, init } = require('./keyvault-emulator') .... .... .... // ...

The dynamically generated hyperlink is not displaying correctly

I've been attempting to display a link on my page, but instead of returning the /register path, it immediately redirects to the UTMs.... The href displayed on the site is domain.com/?utm_campaign... rather than domain.com/register?utm_campaign... ...

Send a property parameter to the Vue component

In my project using Vue and Laravel, I am trying to create a modal window with 2 tabs. The idea is to have two buttons, with each button linked to a specific tab that should open when clicked. These buttons are located in the blade template: <button ...

Is JSON formatting essential for Highcharts? How to divide and preprocess data for creating charts?

Seeking assistance with extracting data from a JSON at the following link: I am attempting to integrate this data into highcharts for visualization. Although I have a functioning chart, I am struggling with properly formatting the JSON mentioned above du ...

Create visual representations using the data displayed in charts generated by Chart JS

Good evening. I am currently utilizing Chart JS in my project to visualize the total count per column in a bar graph. My backend framework is Laravel, and I pass the data from the controller using the variable $datacount. This snippet shows the query in ...

Reading values from a properties file using HTML

Here's a snippet of my HTML code: First name: <input type = "text" > Last name: <input type = "text"> Instead of manually inputting the field values (First name, Last name) in the HTML, I am interested in reading them ...

Aligning dynamically-sized TextInput in React Native

I am facing a challenge in centering a text input with a width that matches the length of the input text. I have tried using alignSelf: 'center' and alignItems: 'center', but the text input is not visible without specifying a width. Fo ...

What is the best way to split text copied from a textarea into <p> paragraphs with an equal number of characters in each?

Check out this JSFiddle version I've found a JSFiddle example that seems perfect for my current project needs. However, I'm wondering how to modify the code to ensure that each paragraph is evenly divided with the same number of characters and a ...

Why is the 'Access-Control-Allow-Origin' header missing in the MEAN stack Facebook authorization error?

Currently, I am working on implementing Facebook authorization in my MEAN stack application. To achieve this, I am utilizing the passport and passport-facebook modules. It's worth mentioning that I have opted not to use jade or ejs, and instead sticki ...

Javascript datatables do not allow for setting a default column sort

I am encountering an issue where I need to sort the results by a specific column on page load. In this case, I want the initial results to be displayed in descending order based on "RecordDate". However, it seems that the server side is blocking any sort ...

What mechanisms do frameworks use to update the Document Object Model (DOM) without relying on a

After delving into the intricate workings of React's virtual DOM, I have come to comprehend a few key points: The virtual DOM maintains an in-memory representation of the actual DOM at all times When changes occur within the application or compo ...

Tips for automatically setting focus to the following cell after inserting a new row in AngularJS

Transitioning from the Knockout world to Angular, I am facing an issue with a key-press event for tab. Whenever I add a new row in the table, the focus shifts to the information icon in the URI bar instead of the next cell in the newly created row. I belie ...

Run the GetServerSideProps function every time the button is clicked

Struggling with my NextJS app development, I encountered an issue while trying to fetch new content from an API upon clicking a button. The server call is successful, but the update only happens when I refresh the page rather than triggering it with the bu ...

Embracing Error Handling with ES6 Promises

I am seeking clarification on how errors travel through a series of then continuations to a catch continuation. Consider the following code: Promise.reject(new Error("some error")) .then(v => v + 5) .then(v => v + 15) .catch(er ...

Angular 4 is displaying an error message indicating that the expression has been modified after being initially verified

I've been utilizing Angular Material within my Angular 4 application. There seems to be an issue when attempting to utilize the MatSnackBar in the ngAfterViewInit(). The error I encounter is as follows: ExpressionChangedAfterItHasBeenCheckedError: ...

What is the best way to conceal the legend in a chart.js component within a React application?

I've been struggling to hide the legend on my Chart.js chart. Per the official documentation (https://www.chartjs.org/docs/latest/configuration/legend.html), hiding the legend requires setting the display property of the options.legend object to fals ...

cPanel is incompatible with node version 12.16.0

I am facing a dilemma regarding hosting my node API, which was built using node version 12.16.0, on cPanel. The available version for node in cPanel is 12.9.0 (Most recent). How should I proceed? Is the node version really a critical factor in this case? ...

The environmental variable remains undefined even after it has been established

I've been experimenting with setting my environment variable in the package.json file so that I can access it in my server.js file. Despite trying NODE_ENV=development, set NODE_ENV=development, cross-env NODE_ENV=development, and export NODE_ENV=deve ...

State in Vuex is failing to update effectively when actions are being utilized

I'm trying to wrap my head around VueX, but I'm having trouble getting Axios to work with it. In my store.js file, I have the following setup: state: { cards: [], currentPage: 1, lastPage: 2, }, actions: { loadGradients(page ...

What is the proper technique for inserting a variable into the header portion of a v-data-table from a JavaScript file?

I'm currently developing an application using Vue.js with datatables. I need to display the headers of a v-data-table component, and ideally, I would like to pass a variable that can be dynamic based on the language selected on the page. Below is the ...