从存储过程填充一个下拉列表

问题描述

我有一个方法Edit,其中我将id发送到stored procedure,然后从数据库表中取回数据。我正在尝试使用从存储过程中获取的数据填充几个下拉列表,但无法正常工作,下拉列表中的值为空。

public IActionResult Edit(int id)
        {
            string conString = configuration.GetConnectionString("DefaultConnection");
            var con = new sqlConnection(conString);
            con.open();

            sqlCommand cmd = new sqlCommand("nobp_LoadSettlementContract",con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("OBJECTID",id);
            
            Model results = new Model();

            using (sqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        Model cs = new Model ();
                        cs.TECHNOLOGY_OBJECTID = dr.GetString(0);
                        cs.DOWNLOAD_SPEED_CLASS_OBJECTID = dr.GetString(1);
                        cs.CustomerType = dr.GetString(2);
                        results = cs;
                    }
                }
        
            
            ViewBag.Technology = new SelectList(results.Technology);
            ViewBag.DownloadSpeed = new SelectList(results.DownloadSpeed);
            ViewBag.CustomerType = new SelectList(results.CustomerType);
            return View(results);

}   

这是我的观点

            <div class="col-lg-6">
                @Html.DropDownListFor(model => model.Technology,ViewBag.Technology as SelectList,"please choose",new { @name = "Technology",@id = "TechnologyID",@class = "form-control chosen",required = "required" })
            </div>

我也尝试过这样的事情

ViewBag.Technology = new SelectList(results.Technology,"TECHNOLOGY_DESCRIPTION");

但是我无法正常工作。任何想法如何进行?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...