我正在使用Asp.net MVC5和實體框架。我是兩種技術中的新功能。在mvc實體框架的下拉選擇中填充文本框
基本上我創建一個窗體,在這個窗體中可用的DropDown,當我從DropDown中選擇值。我想填寫此表單上也有的文本框。
這是我的控制器
public class ChainController : Controller
{
private hcEntities db = new hcEntities();
// GET: Chain
public ActionResult Index()
{
ViewBag.name = new SelectList(db.chains,"code","name");
return View(db.chains.ToList());
}
}
查看: -
<div class="form-horizontal">
<hr />
<div class="form-group">
<label class="col-sm-2 control-label">
Select Chain
</label>
<div class="col-md-3">
@Html.DropDownList("name" , null, new { @class = "form-control" })
</div>
</div>
@using (@Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-group">
<label class="col-sm-2 control-label">
Chain UserName
</label>
<div class="col-md-3">
@Html.TextBox("ChainName", null, new { @class = "form-control" }) //WHAT DO I DO HERE???????
</div>
</div>
}
</div>
模型(chain.cs由EF生成)
public partial class chain
{
public long chain_id { get; set; }
public string name { get; set; }
public string code { get; set; }
public string username { get; set; }
public string password { get; set; }
public long created_by { get; set; }
public System.DateTime created_on { get; set; }
public Nullable<long> updated_by { get; set; }
public Nullable<System.DateTime> updated_on { get; set; }
public chain()
{
created_by = 1;
created_on = DateTime.Now;
}
}
我不知道下一步會是什麼。如何填充文本框的值爲用戶名從下拉列表中選擇。 我在stackoverflow中找到太多的答案,但我填寫這些對我沒有幫助。例如 fill the textboxes with selecting dropdownlist in mvc,How to populate a textbox based on dropdown selection in MVC..?
幫幫我!
什麼'chain'表的主鍵? – ekad 2014-09-25 07:55:49