【发布时间】:2014-09-25 05:28:23
【问题描述】:
我正在使用 Asp.net MVC5 和 Entity Framework。我是这两种技术的新手。
基本上我创建一个表单,在这个表单中,当我从 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>
模型(EF生成的chain.cs)
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;
}
}
我不知道下一步会是什么。如何从下拉列表的选择中用 Username 的值填充文本框。 我在stackoverflow中找到了太多答案,但我填写这些对我没有帮助。例如 fill the textboxes with selecting dropdownlist in mvc, How to populate a textbox based on dropdown selection in MVC..?
帮帮我!
【问题讨论】:
-
chain表的主键是什么?
标签: c# asp.net-mvc entity-framework