本文介绍了我的下拉列表在创建视图中正常工作。但在编辑视图中,此下拉列表未加载对象原始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的下拉列表,它在创建视图中正常工作。但在编辑视图中,此下拉列表未加载对象原始值



This is my dropdown list which is working fine in create view. but in edit view this dropdown did not load object original values

@Html.DropDownListFor(model => model.FundingSource, new List<selectlistitem>
                {new SelectListItem {Text = "ADP", Value = "ADP"},
                 new SelectListItem {Text = "CG", Value = "CG"},
                 new SelectListItem {Text = "ADP(D)", Value = ADP(D)"},                   
                 new SelectListItem {Text = "Others", Value = "Others"}                         
               },--Select--,new {@class="form-control"})





我的尝试:





What I have tried:

@Html.DropDownListFor(model => model.FundingSource, new List<SelectListItem>
                {new SelectListItem {Text = "ADP", Value = "ADP"},
                 new SelectListItem {Text = "CG", Value = "CG"},
                 new SelectListItem {Text = "ADP(D)", Value = ADP(D)"},                   
                 new SelectListItem {Text = "Others", Value = "Others"}                         
               }, --Select--,new {@class="form-control"})

推荐答案

@Html.DropDownListFor(model => model.FundingSource, new SelectList(new List<SelectListItem>
            {new SelectListItem {Text = "ADP", Value = "ADP"},
             new SelectListItem {Text = "CG", Value = "CG"},
             new SelectListItem {Text = "ADP(D)", Value = "ADP(D)"},
             new SelectListItem {Text = "Others", Value = "Others"}
           }, "Text", "Value", Model.FundingSource), "--Select--",new {@class="form-control"})


这篇关于我的下拉列表在创建视图中正常工作。但在编辑视图中,此下拉列表未加载对象原始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 22:24