SelectListItem selected = true not working in view

前端 未结 6 1931
醉酒成梦
醉酒成梦 2021-02-07 09:36

I have a gender select field (--Select--, Male, Female) and I\'m populating that in my controller. When the page loads, I want the gender that is selected in the model pm.

6条回答
  •  旧时难觅i
    2021-02-07 10:07

    Try this;

    public static List ListSexo { get; } = new List
        {
            new SelectListItem{Selected =true, Value="N", Text="Seleccione"},
            new SelectListItem{Value="F", Text="Femenino"},
            new SelectListItem{Value="M", Text="Masculino"}
        };
    
    
    

提交回复
热议问题