Click here to Skip to main content
15,846,727 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am working on a C# E-Commerce application.

I having difficulties deleting and adding a item to the cart. It gives me the error in the price column which is a decimal field.

The application only executes the delete/add to cart when I change this decimal value to a normal integer value without decimals.

How can I change the Detail.cshtml file to counter this issue?

Please view the links for the 2 images below:
https://i.stack.imgur.com/ZzXg0.png
https://i.stack.imgur.com/KeVkW.png

What I have tried:

I have tried editing validation in the Detail.cshtml. I have also changed the Price field in the Detail.cshtml to editable to test whether the normal number can be used.
Posted
Updated 8-Mar-23 15:59pm
Comments
Richard MacCutchan 12-Nov-22 8:42am    
Please use the Improve question link above, and add complete details of what is not working, including the failing code.

1 solution

I have looked briefly at the code image you provided and didn't see any JavaScript, so I'm not sure if this suggestion will make sense. However, it is a common technique to use JavaScript to test form input.

This small JS function isMoney uses regex to check for digits then an optional decimal point and then allows 0 to 2 digits after that decimal point.

function isMoney(input) {
    var regex = /^\d+(?:\.\d{0,2})$/;
    return regex.test(input);
}


In the form itself, you call the function and branch accordingly. e.g.

var input = document.getElementById("Price").value;
if (isMoney(input)) {
    // Input is valid
} else {
    // Input is not valid
}


I'm not sure how this suggestion fits into the code style you are using, hopefully it is helpful.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900