I'm using MVC 2 for a project and I'm having a problem with a view. In the controller I have the code:
return View(calendarDay);
If I debug this line and inspect calendarDay it tells me the calendarDay.Id property is equal to 2. In the view I have some code like this:
<%: Html.HiddenFor(model => model.Id) %>
However, when the view is shown after binding it to a calendarDay with Id 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 the TryUpdateModel(calendarDay) it gets the Id property 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. Anyone knows what I might be doing wrong?