You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The GetSelectListWithDefaultValue method modifies the selectList given as a parameter. A copy of the list is made, but selectList is modified (specifically the Selected properties) as part of the process and since the object is passed by reference, the original object is modified. This is confusing behavior.
Here's an example of where this can cause confusion:
@Html.DropDownListFor(model => model.Field1, Model.SelectListItems)
@Html.DropDownListFor(model => model.Field2, Model.SelectListItems)
If Field1 has a value set but Field2 is null, Field1 will still render with the value of Field1 set since Model.SelectListItems will have had Selected set to true for that SelectListItem.
If anything, the documentation should be updated to note this effect. Resolving this bug could be a breaking change—I imagine there is existing code that depends on this behavior.
The text was updated successfully, but these errors were encountered:
It was determined that the developers were "we are concerned that some users might have taken dependency on the behavior (although this is probably rare)."
The GetSelectListWithDefaultValue method modifies the selectList given as a parameter. A copy of the list is made, but selectList is modified (specifically the Selected properties) as part of the process and since the object is passed by reference, the original object is modified. This is confusing behavior.
src/System.Web.Mvc/Html/SelectExtensions.cs
Here's an example of where this can cause confusion:
@Html.DropDownListFor(model => model.Field1, Model.SelectListItems)
@Html.DropDownListFor(model => model.Field2, Model.SelectListItems)
If Field1 has a value set but Field2 is null, Field1 will still render with the value of Field1 set since Model.SelectListItems will have had Selected set to true for that SelectListItem.
If anything, the documentation should be updated to note this effect. Resolving this bug could be a breaking change—I imagine there is existing code that depends on this behavior.
The text was updated successfully, but these errors were encountered: