View MVC 2 with incorrect model information

I am using MVC 2 for a project and I have a problem with the view. In the controller, I have the code:

return View(calendarDay);

If I debug this line and check calendarDay, it tells me that the calendarDay.Id property is 2. In the view, I have this code:

<%: Html.HiddenFor(model => model.Id) %>

However, when the view is shown after binding it to calendarDay with identifier property = 2, I get this on the generated HTML:

<input id="Id" name="Id" type="hidden" value="1">

The value is 1, so when I do TryUpdateModel (calendarDay), it gets the Id property equal to 1 instead of 2, and when I go to the repository to get the object to delete it, it crashes because it finds the wrong one- Does anyone know what I can do wrong?

0
2

, POSTED ( 1) 2. , , HTML- , : POSTED . , HiddenFor , .

:

<input type="hidden" name="Id" value="<%: Model.Id %>" />

@jfar , , post :

MoselState.Clear();
+1

, , , . .

0

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


All Articles