在ASP.NET MVC实体框架中使用JavaScript根据下拉列表选择填充多个文本框

问题描述

我正在使用Asp.net MVC5和Entity Framework。这两种技术都是新手。

基本上我创建一个窗体,当我从DropDown中选择值时,在此窗体中有一个DropDown可用。我想填写文本框,该框也可以在此表单上使用。

控制器:

map(select(.location=="Stockholm"))

剃刀视图:

public ActionResult Create()
    {
        var listrang = db.Ranglists.ToList();
        ViewBag.listRangs = new SelectList(listrang,"RangId","Nom","Cour","td","tp");
        return View();
    }

 public ActionResult Action(string Nom)
    {
        var query = from c in db.Ranglists where c.Nom == Nom select new {nom = c.Nom,cour = c.Cour,Td = c.td,Tp =c.tp };
        return Json(query,JsonRequestBehavior.AllowGet);
    }

最终功能Javascript

    <div class="form-group">
        @Html.LabelFor(model => model.Rang,htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.DropDownListFor(model => model.Rang,ViewBag.listRangs as SelectList,"choose",htmlAttributes: new { onchange = "Action(this.value);",@class = "form-control" })
            @Html.ValidationMessageFor(model => model.Rang,"",new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(model => model.Cours,htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Cours,new { htmlAttributes = new { @class = "form-control",@id = "cour" } })
            @Html.ValidationMessageFor(model => model.Cours,new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Tds,htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Tds,@id = "td" } })
            @Html.ValidationMessageFor(model => model.Tds,new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Tps,htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Tps,@id = "tp" } })
            @Html.ValidationMessageFor(model => model.Tps,new { @class = "text-danger" })
        </div>
    </div>

但不起作用

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)