Last post May 22, 2018 09:04 AM by afrika
May 21, 2018 01:35 PM|afrika|LINK
1. I created a modal popup which generated a partial view with my model.
2. Now I am using a JQuery-Ajax post to submit to the controller.
Problem is that both Jquery and the serverside validation tells me my model is not valid. All the values have data in them and I tried adding fake values on the controller, however it keeps telling me the model is not valid. It says the first 5 fields are
null. In the line
var errors = ModelState.Values.SelectMany(v => v.Errors);
ERROR MESSAGE - on further expansion, it says all first 5 fields are null, when I have assigned them above
May 21, 2018 01:47 PM|mgebhard|LINK
Null parameters indicate an issue on the client usually the input parameters do not match the action input or are simply not sent. Since we cannot see your code there is not much we can do to provide assistance.
Use the browser's dev tools to debug the client side script. Otherwise, post a code sample that reproduces this issue.
May 21, 2018 01:55 PM|PatriceSc|LINK
ModelState is to check the posted model used by the model binder. Assigning value from your code won't change anything. So for now it seems your Ajax request reallly doesn't post required values to your model. You could perhaps try F12 Network to double
check the payload.
May 22, 2018 09:04 AM|afrika|LINK
I did not post my code, because its far too complex with layout page, main page and a modal popup and tonnes of scripting. I just wanted to know why the assigned values did not work (As a fake model binder) But now Its clear. I have edited my model class
file and set the 5 fields that are null as NOT REQUIRED and its ok now, so I have to make sure its properly binded by the calling client