问题描述
我有一个方法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 (将#修改为@)