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










share|improve this question
























  • 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















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










share|improve this question
























  • 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













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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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


















  • 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
















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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...