简体   繁体   中英

C# ASP.NET MVC 5 ViewModel issue

I have a ViewModel defined, that represents the required properties. Using this ViewModel to define the view with razor.

The HttpPost action gets the ViewModel as parameter. I can see all parameters in the POST command if check with Request.Form.AllKeys and also in the action argument, that is the ViewModel.

If I change the ViewModel class, ie take some properties out, or add some properties and use them in the view all works fine.

Only one boolean property I can not remove, without leaving a hidden input field with the id of that property in the view.

If I remove it, the ViewModel argument in the HttpPost action doesn't get the changes of all boolean properties of the ViewModel when clicked those checkboxes in the view, but I can see with Request.Form.AllKeys all parameters in the POST command.

I don't understand what happens there.

I 've found out what has caused the error. The javascript code, that is handling the clicks of the checkboxes, still contained the function for the already removed ID. That forced the javascript code to stop running the other functions, and the other checkboxes kept the old status==false. So the values of those properties in the ViewModel never changed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM