When the front page is displayed, Html.DropDownListFor cannot select the existing value problem

1. The background value is the drop-down box, and the set value is as follows:

ViewBag.IAccessStyle = DropDownList_DictValue("Access Scheme", model.IAccessStyle);

2. The front desk uses @Html.DropDownListFor to display the "Access Plan" drop-down box, the code is as follows

 @Html.DropDownListFor(m => m.IAccessStyle, ViewBag.IAccessStyle as SelectList, "Please select an access scheme")

 

In this case, the display on the front page cannot display the existing value of the option, and only displays "Please select an access plan".

After inspection, when the background passes values ​​to the foreground, the "IAccessStyle" of ViewBag.IAccessStyle is the same as the access scheme field of the entity class. If ViewBag.IAccessStyle is modified to ViewBag._IAccessStyle, it can be displayed normally.

That is, the value of ViewBag cannot be the same as the field name of the entity class.

It can be displayed normally:

1. The background value is the drop-down box, and the set value is as follows:

ViewBag._IAccessStyle = DropDownList_DictValue("Access Scheme", model.IAccessStyle);

2. The front desk uses @Html.DropDownListFor to display the "Access Plan" drop-down box, the code is as follows

 @Html.DropDownListFor(m => m.IAccessStyle, ViewBag._IAccessStyle as SelectList, "Please select an access scheme")

 

@Html.DropDownList has the same problem.

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326865809&siteId=291194637