The model state is not valid for the decimal value of 2000.00

I'm running into an issue validating 1 instance of my model medewerker_functie.

Within that Model, I have 3 instances that are decimals. Two of them - uren at 40.0 and fulltime_salaris at 2200.00, are being validated correctly while the salaris isn't.

In the process of handling the values within the Actionresult Create, they are being received as strings due to JavaScript conversion:

onblur="$(this).val(parseFloat($(this).val()).toFixed(2))"

However, despite attempts to convert the values using parseFloat(), the value for salaris remains a string.

This is reflected in my code snippet:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ID,medID,functieID,type_contract,startdatum,einddatum,aantal_uur,aantal_dagen,fulltime_salaris,salaris")] medewerker_functie medewerker_functie, int medID, int functieID, string contract, DateTime startDate, DateTime? endDate, String uren, int dagen, String fulltime, String salaris)
{
   // Code implementation here
}

The confusion lies in the fact that fulltime_salaris and uren accept values properly, but not salaris. The fields in question are specified as decimals in both the model and the database.

During debugging, it was discovered that the AJAX call returns the correct values but they remain as strings when processed in the backend code. This discrepancy has caused issues with validation.


EDIT

The AJAX call also confirms the initial issue with data types:

// Console log output and AJAX call code here

Answer №1

I was able to resolve the issue by renaming the parameter String salary. It seems that there was a conflict with the Bind parameter Salary, so I replaced it with dec_salary in the Model. However, the ModelState.IsValid was still referencing the original string parameter Salaris, causing it to be invalid.

A big thank you to everyone who helped me out!

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

Keep deciphering in a loop until the URI string matches

I have a task to decode a string URI until there are no more changes. The string URI I am working with typically has around 53,000 characters, so the comparison needs to be fast. For demonstration purposes, I have used a shortened version of the string. B ...

Send an object to a thread and retrieve it once the thread has finished processing

Let me be upfront about this - I am not an expert in threading. While I have experience as a senior C# web developer, I am currently working on a project that involves populating numerous objects which require time-consuming WebRequests and Responses. Init ...

Creating a horizontal grid with a set number of rows using ng-repeat

I'm facing a challenge where I need to showcase a set of text objects stored in an array within a grid format. I am utilizing the Ionic framework for this purpose. Here are the specifications for the grid: It should have a fixed height Consist of e ...

Selecting multiple images by holding Ctrl key and uploading them through PHP

Looking for guidance on creating a Facebook-like multiple image uploader in my PHP project. The user should be able to select multiple files with Ctrl+click. Anyone know of a suitable jQuery plugin or have some sample code handy? Appreciate any help. Than ...

How can I extract text within a specific HTML tag using Selenium?

On my second day of learning Selenium, I am looking to extract text from within specific HTML tags. Here is a sample of the HTML code: <div id="media-buttons" class="hide-if-no-js"/> <textarea id="DescpRaw" class="ckeditor" name=" ...

Adjustable div height

I am facing an issue with a container that displays products. The container is currently set to only show a few products, but there is a button that increases the height to display all products. The problem is that the height needs to change dynamically ba ...

Converting a class component into a functional component: utilizing hooks

I am currently in the process of converting a class component to a functional component, but I am encountering difficulties when trying to call the 'resize' method of the child component 'Dog.js' App.js function App(props) { useEffe ...

Protractor obtainElementProperty awaiting - fulfilling result

We are encountering an issue where we are trying to store a value from the getAttribute function in a local variable, but resolving the promise seems to be problematic for us. return element(by.id('foo')).getAttribute('value'); This c ...

Determining the matrix coordinates corresponding to a specific screen position

Currently, I am in the process of creating my version of Pacman using XNA and .NET. To maintain a consistent design, I have established a screen size of 448x576 with a matrix size of 28x36. Each position in the matrix corresponds to a square of 16px by 16 ...

Prevent right-clicking on links from a particular domain

Looking to prevent right-clicking on a link? Check out this code snippet: <script type="text/javascript" language="javascript> $(document).ready(function() { $('body').on('contextmenu', 'a', function(e){ ...

Focus is lost on React input after typing the initial character

Whenever I input text, the focus is lost. All my other components are working fine except this one. Any ideas why this might be happening? I attempted to create separate components and render them in my switch statement, but it still doesn't work. O ...

Search Azure table storage to optimize data retrieval speed in C#

My ATS table has a Partition key and Row Key structured like this: PartitionKey RowKey US_W|000000001 0000200325|0184921077191606273 US_W|000000004 0000200328|0184921077191606277 US_W|000000005 XXXXXXXXXX|XX(somenumbers)XXXX To clarify, ...

Determining Browser Activity and Focus with C# Selenium

I have a need to send key inputs to various browser sessions and ensure that the correct session is active. I have implemented the following method and it is currently working: [DllImport("user32.dll")] private static extern IntPtr GetForegroundWindow(); ...

What is the best way to perform a callback after a redirect in expressjs?

After using res.redirect('/pageOne') to redirect to a different page, I want to call a function. However, when I tried calling the function immediately after the redirect like this: res.redirect('/pageOne'); callBack(); I noticed th ...

I am having trouble with my quiz function as it only checks the answer correctly for the first question. Does anyone have suggestions on how to make it work for

Currently, I'm tackling a quiz project that was assigned to me during my bootcamp. My focus right now is on the checkAnswer function, which evaluates the answer selected by the player. const startButton = document.querySelector(".start") as ...

Sending Objects Array in POSTMAN using Hapijs: A Step-by-Step Guide

Could you please assist me on how to send a POST request in POSTMAN for the given array of objects and then validate it using Joi in a hapi server? var payload = [{ name: 'TEST Name 1', answer: 'TEST Answer 1', category: &a ...

The Angular JS validation feature does not seem to be functioning correctly when used in conjunction with Bootstrap's

I'm currently working on a form that utilizes AngularJS and Bootstrap for validation. Everything was functioning properly until I introduced typeahead functionality - the validation no longer triggers when selecting values from typeahead. Is there a ...

What sets apart "React.useState setter" from "this.setState" when updating state?

After clicking on the button in AppFunctional, the component fails to update even though the state has changed. However, everything works fine in AppClass. In both cases, we are mutating the original state with "push", but I'm struggling to understan ...

The ion-col with col-3 is causing a template parse error

Currently, I am facing an issue while trying to print data from a constructor. Everything is working fine until I added col-3 to ion-col. It seems like I missed including some module, but I am not sure which one. This is my home.ts file: import { Compone ...

Is the return value a result of destructuring?

function display(): (number, string) { return {1,'my'} } The code above is displaying an error. I was hoping to use const {num, my} = print(). How can I correctly specify the return type? ...