在视图中,如果我选择id,我想直接从表格到文本中检索多个列

时间:2017-05-22 08:59:05

标签: c# asp.net asp.net-mvc

我想在用户选择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 ....... 
如果有人知道,请告诉我

0 个答案:

没有答案