微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决在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 举报,一经查实,本站将立刻删除。