0

I've got a little drag-and-drop thing going on, where a hidden field is populated using JavaScript. The idea is that this hidden field's modified property will go back to the server as normal. The problem is that the ModelState hasn't recognised that the value has changed- I've got an error saying the value's null when it's clearly not (it doesn't actually have a required flag on it, but it's an int, so the mere fact that it's null causes MVC to throw a tantrum).

So I was just wondering if, in JavaScript, I can modify the ModelState's errors to get rid of the error.

user2564511
  • 257
  • 1
  • 6
  • 14
  • One way to resolve this problem is that when u r posting data and checking modalstate.isvalid just above it use modalstate.remove("//Propert name")...it will help u.. –  Jul 07 '14 at 09:17
  • Perhaps this [answer](http://stackoverflow.com/a/14992504) may help. – chridam Jul 07 '14 at 09:26
  • You can use `if (ModelState.ContainsKey("key")) ModelState["key"].Errors.Clear();`, but wouldn't it be better to fix the error in your javascript –  Jul 07 '14 at 09:38

1 Answers1

0

It actually turns out the problem was something completely different to what I thought- long story short, it was actually telling the truth and it was caused by another problem I already knew about and was easily fixed. I probably should've trusted MVC more.

Thanks anyway for the help. There are generally better ways than what I was trying to do (removing validation instead of just fixing the problem), so the question was a bit stupid.

user2564511
  • 257
  • 1
  • 6
  • 14