Clear errors from ModelState after errors fixed by user
up vote
-1
down vote
favorite
I'm working on a project at the moment where a user has to input some stuff, I validate what get's send to the backend and I throw some validation errors when it's not the desired data.
The errors I get back from the ModelState I show in the frontend. After the user corrects his mistake, it should be send to the backend.
When the user makes another mistake after the first one, he gets shown double the amount of errors in the frontend because the ModelState errors don't get cleared for some reason and they get pushed back into the frontend array that I display to the user.
How do I fix this issue? Can I remove the errors from the ModelState?
Some more info about this issue can be found here: Angular 7 + ASP.NET Core - validating input on model, remove errors
angular typescript asp.net-core
add a comment |
up vote
-1
down vote
favorite
I'm working on a project at the moment where a user has to input some stuff, I validate what get's send to the backend and I throw some validation errors when it's not the desired data.
The errors I get back from the ModelState I show in the frontend. After the user corrects his mistake, it should be send to the backend.
When the user makes another mistake after the first one, he gets shown double the amount of errors in the frontend because the ModelState errors don't get cleared for some reason and they get pushed back into the frontend array that I display to the user.
How do I fix this issue? Can I remove the errors from the ModelState?
Some more info about this issue can be found here: Angular 7 + ASP.NET Core - validating input on model, remove errors
angular typescript asp.net-core
Your question isn't clear.ModelState
is constructed anew with each set of post data. So, after you make a new post, the only errors that will be present are the errors concerning that particular post, not some previous post. It's possible that the issue is that you're manipulating some client-side representation ofModelState
, in which case, you should be overwriting that with the return from your AJAX each time, not just adding to it. However, it's not clear exactly what you're doing here. You should post some code.
– Chris Pratt
Nov 21 at 13:51
And for some reason, the ModelState still pushes in, e.g.: if on first post the user had 2 mistakes, and on second post the user still has 2 mistakes, the second time he gets 4 warnings, etc. It's weird, I know. This was not behavior I was expecting. The code I used for this project is on the other question by me. Linked in this question.
– VincentVH
Nov 21 at 15:46
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I'm working on a project at the moment where a user has to input some stuff, I validate what get's send to the backend and I throw some validation errors when it's not the desired data.
The errors I get back from the ModelState I show in the frontend. After the user corrects his mistake, it should be send to the backend.
When the user makes another mistake after the first one, he gets shown double the amount of errors in the frontend because the ModelState errors don't get cleared for some reason and they get pushed back into the frontend array that I display to the user.
How do I fix this issue? Can I remove the errors from the ModelState?
Some more info about this issue can be found here: Angular 7 + ASP.NET Core - validating input on model, remove errors
angular typescript asp.net-core
I'm working on a project at the moment where a user has to input some stuff, I validate what get's send to the backend and I throw some validation errors when it's not the desired data.
The errors I get back from the ModelState I show in the frontend. After the user corrects his mistake, it should be send to the backend.
When the user makes another mistake after the first one, he gets shown double the amount of errors in the frontend because the ModelState errors don't get cleared for some reason and they get pushed back into the frontend array that I display to the user.
How do I fix this issue? Can I remove the errors from the ModelState?
Some more info about this issue can be found here: Angular 7 + ASP.NET Core - validating input on model, remove errors
angular typescript asp.net-core
angular typescript asp.net-core
edited Nov 21 at 8:25
Tân Nguyễn
1
1
asked Nov 21 at 8:19
VincentVH
15
15
Your question isn't clear.ModelState
is constructed anew with each set of post data. So, after you make a new post, the only errors that will be present are the errors concerning that particular post, not some previous post. It's possible that the issue is that you're manipulating some client-side representation ofModelState
, in which case, you should be overwriting that with the return from your AJAX each time, not just adding to it. However, it's not clear exactly what you're doing here. You should post some code.
– Chris Pratt
Nov 21 at 13:51
And for some reason, the ModelState still pushes in, e.g.: if on first post the user had 2 mistakes, and on second post the user still has 2 mistakes, the second time he gets 4 warnings, etc. It's weird, I know. This was not behavior I was expecting. The code I used for this project is on the other question by me. Linked in this question.
– VincentVH
Nov 21 at 15:46
add a comment |
Your question isn't clear.ModelState
is constructed anew with each set of post data. So, after you make a new post, the only errors that will be present are the errors concerning that particular post, not some previous post. It's possible that the issue is that you're manipulating some client-side representation ofModelState
, in which case, you should be overwriting that with the return from your AJAX each time, not just adding to it. However, it's not clear exactly what you're doing here. You should post some code.
– Chris Pratt
Nov 21 at 13:51
And for some reason, the ModelState still pushes in, e.g.: if on first post the user had 2 mistakes, and on second post the user still has 2 mistakes, the second time he gets 4 warnings, etc. It's weird, I know. This was not behavior I was expecting. The code I used for this project is on the other question by me. Linked in this question.
– VincentVH
Nov 21 at 15:46
Your question isn't clear.
ModelState
is constructed anew with each set of post data. So, after you make a new post, the only errors that will be present are the errors concerning that particular post, not some previous post. It's possible that the issue is that you're manipulating some client-side representation of ModelState
, in which case, you should be overwriting that with the return from your AJAX each time, not just adding to it. However, it's not clear exactly what you're doing here. You should post some code.– Chris Pratt
Nov 21 at 13:51
Your question isn't clear.
ModelState
is constructed anew with each set of post data. So, after you make a new post, the only errors that will be present are the errors concerning that particular post, not some previous post. It's possible that the issue is that you're manipulating some client-side representation of ModelState
, in which case, you should be overwriting that with the return from your AJAX each time, not just adding to it. However, it's not clear exactly what you're doing here. You should post some code.– Chris Pratt
Nov 21 at 13:51
And for some reason, the ModelState still pushes in, e.g.: if on first post the user had 2 mistakes, and on second post the user still has 2 mistakes, the second time he gets 4 warnings, etc. It's weird, I know. This was not behavior I was expecting. The code I used for this project is on the other question by me. Linked in this question.
– VincentVH
Nov 21 at 15:46
And for some reason, the ModelState still pushes in, e.g.: if on first post the user had 2 mistakes, and on second post the user still has 2 mistakes, the second time he gets 4 warnings, etc. It's weird, I know. This was not behavior I was expecting. The code I used for this project is on the other question by me. Linked in this question.
– VincentVH
Nov 21 at 15:46
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407788%2fclear-errors-from-modelstate-after-errors-fixed-by-user%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your question isn't clear.
ModelState
is constructed anew with each set of post data. So, after you make a new post, the only errors that will be present are the errors concerning that particular post, not some previous post. It's possible that the issue is that you're manipulating some client-side representation ofModelState
, in which case, you should be overwriting that with the return from your AJAX each time, not just adding to it. However, it's not clear exactly what you're doing here. You should post some code.– Chris Pratt
Nov 21 at 13:51
And for some reason, the ModelState still pushes in, e.g.: if on first post the user had 2 mistakes, and on second post the user still has 2 mistakes, the second time he gets 4 warnings, etc. It's weird, I know. This was not behavior I was expecting. The code I used for this project is on the other question by me. Linked in this question.
– VincentVH
Nov 21 at 15:46