The entity changes between the controller and the view.

How is this possible? ControllerViewViewcode

Two days fit. If anyone has a reasonable explanation, that would be good.

Note that if I delete EditorFor(o => o.DocumentParentID) , the value will be changed to 0 if it is received in [HttpPost], so it corresponds to another DB entry

Please note that these are related entries in the database. enter image description here

+4
source share
2 answers

You get a value of 6 for the ID property, since it matches the Id parameter on your route. It seems that the default mediator is also looking for these properties in your URL.

Change the parameter name for your action method or the name of the ID property in the StatusClient class, and it should work fine.

Also, if you do not add EditorFor(o => o.DocumentParentID) in your view, DocumentParentID will not be sent back to your action method, and you will get a default value of 0.

+7
source

I'm not quite sure what you are asking, but I think why this is) by default in DocumentParentID when EditorFor is not on the page?

Modelbinder will bind the default value for the object type, so if you define DocumentParentID as Int32, the binder model will bind to 0 in the message. If the DocumentParentID is defined as Int32?, Then the binding model will bind to the null value in the message.

0
source

Source: https://habr.com/ru/post/1432732/


All Articles