Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Created Issue: DropDownListFor, value of lambda is not using in the initial display [853]

$
0
0
When using DropDownListFor items from being selected during the initial display of the drop-down list for the value of the property specified in the lambda expression is not used.

Because the value in the ViewData is used after POST, the item is selected correctly.

The sample code is as follows:

```
public ActionResult Index()
{
// create SelectList (sample values)
ViewBag.Category = new SelectList(Enumerable.Range(1, 5));

return View(new FormModel
{
// set default value
Category = 3,
});
}
```

```
@* use expression helper, "3" item is not selected. *@
@Html.DropDownListFor(model => model.Category, null)
```

Take a look at my blog. It is with screenshots.
[When combined with ViewBag and DropDownListFor problem](http://www.microsofttranslator.com/bv.aspx?from=&to=en&a=http://shiba-yan.hatenablog.jp/entry/20130207/1360226954)

Viewing all articles
Browse latest Browse all 7215

Trending Articles