Skip to content

Latest commit

 

History

History
54 lines (39 loc) · 5.06 KB

File metadata and controls

54 lines (39 loc) · 5.06 KB
uid mvc/overview/getting-started/mvc-learning-sequence
title MVC recommended tutorials and articles | Microsoft Docs
author Rick-Anderson
description This page contains links to ASP.NET MVC tutorials and a suggested sequence to follow them.
ms.author tdykstra
ms.date 05/22/2015
ms.assetid 8513a57a-2d45-4d6b-881c-15a01c5cbb1c
msc.legacyurl /mvc/overview/getting-started/mvc-learning-sequence
msc.type authoredcontent

MVC recommended tutorials and articles

by Rick Anderson

Getting Started

Working with data

Security

Azure

ASP.NET MVC DropDownListFor with SelectListItem

When using the xref:System.Web.Mvc.Html.SelectExtensions.DropDownListFor%2A helper and passing to it the collection of SelectListItem from which it is populated, the DropdownListFor modifies the passed collection after it is called. DropdownListFor changes the SelectListItems Selected properties to whatever was selected by the dropdown list. This leads to unexpected behavior.

The xref:System.Web.Mvc.Html.SelectExtensions.DropDownListFor%2A, xref:System.Web.Mvc.Html.SelectExtensions.DropDownList%2A, xref:System.Web.Mvc.Html.SelectExtensions.EnumDropDownListFor%2A, xref:System.Web.Mvc.Html.SelectExtensions.ListBox%2A, and xref:System.Web.Mvc.Html.SelectExtensions.ListBoxFor%2A update the Selected property of any IEnumerable<SelectListItem> passed or found in ViewData.

The workaround is to create separate enumerables, containing distinct SelectListItem instances, for each property in the model.

For more information, see GetSelectListWithDefaultValue Modifies IEnumerable<SelectListItem> selectList