我想在用户选择electionName
后动态选择electionId
。
型号:
public virtual int ElectionId { get; set; }
public virtual string ElectionName { get; set; }
控制器:
public ActionResult Index(votingModel chk)
{
var id = chk.ElectionId;
if (db.votingModels.Find(id) == id)
{
// i want to do like this directly to the textbox is possible
//string name = "select electionName from tabel where electionId =id";
}
一旦用户直接输入了id文本,选择名称就会出现在视图中。
查看:
@model election.Models.votingModel
@{
ViewBag.Title = "index";
}
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@*<p>
@Html.ActionLink("Create New", "Create")
</p>*@
@Html.Label("election ID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.ElectionId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ElectionId, "", new { @class = "text-danger" })
</div>
@Html.Label("election name", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.ElectionName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ElectionName, "", new { @class = "text-danger" })
@Html.Label("election Reason", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.Reason, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.reason, "", new { @class = "text-danger" })
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="submit" class="btn btn-default" />
</div>
</div>
etc .......
如果有人知道,请告诉我