DropDownListFor - does not select “Selected” value

前端 未结 2 693
广开言路
广开言路 2021-01-11 11:14

Another one of these questions regarding DropDownListFor not selecting the \"Selected\" value. Here is code:

Model:



        
2条回答
  •  抹茶落季
    2021-01-11 11:21

    Ok, let's discuss about your example, when PermissionId was int. You posted model of type CreateEditAccountModel to view. When you created this model, PermissionId equal 0 (default value of int). And DropDownListFor in view get this value. Therefore you had no selected values. When you used string type, default value of PermissionId was null, therefore `DropDownListFor taken default value of SelectList.

    In this case it's better to use int? or Nullable type for PermissionId.

提交回复
热议问题