当前位置: 首页 > 知识库问答 >
问题:

在ASP.NET MVC5中编辑连接表时完成下拉列表

隆兴修
2023-03-14
        if (q != null)
        {
            return View(q);
        }
        else
        {
            return RedirectToAction("ShowPerson", "Home");
        }
    }


    [HttpPost]
    public ActionResult EditPerson(Person per)
    {
        var q = (from a in db.Person
                 where a.ID.Equals(per.ID)
                 select a).SingleOrDefault();

        q.FirstName = per.FirstName;
        q.LastName = per.LastName;
        q.UserName = per.UserName;
        q.EvidenceID = per.EvidenceID;
        q.Mobile = per.Mobile;
        q.Stutus = false;
        q.CodeMelli = per.CodeMelli;
        q.CityID = per.CityID;
        q.Address = per.Address;
        q.Access = per.Access;
        q.Email = per.Email;
        q.Image = per.Image;

        db.Person.Attach(q);
        db.Entry(q).State = System.Data.Entity.EntityState.Modified;
        db.SaveChanges();

        return RedirectToAction("ShowPerson", "Home");
    }


    [HttpGet]
    public ActionResult CreatePerson()
    {

        return View();
    }


    [HttpPost]
    public ActionResult CreatePerson(Person per)
    {
        Person p = new Person();

        p.FirstName = per.FirstName;
        p.LastName = per.LastName;
        p.UserName = per.UserName;
        p.EvidenceID = per.EvidenceID;
        p.Mobile = per.Mobile;
        p.Stutus = false;
        p.CodeMelli = per.CodeMelli;
        p.CityID = per.CityID;

        p.Address = per.Address;
        p.Access = per.Access;
        p.Email = per.Email;
        p.Image = per.Image;

        db.Person.Add(p);
        db.SaveChanges();

        return RedirectToAction("ShowPerson", "Home");
    }
        <div class="form-group">

@html.labelfor(模型=>model.cityid,htmlAttributes:new{@class=“control-label col-MD-2”})@html.editorfor(模型=>model.cityid,new{htmlAttributes=new{@class=“form-control”}})@html.validationmessagefor(模型=>model.cityid,“”,new{@class=“text-danger”})

        <div class="form-group">

@html.labelfor(模型=>model.evidenceid,htmlAttributes:new{@class=“control-label col-MD-2”})@html.editorfor(模型=>model.evidenceid,new{htmlAttributes=new{@class=“form-control”}})@html.validationmessagefor(模型=>model.evidenceid,“”,new{@class=“text-danger”})

共有1个答案

凌俊材
2023-03-14

你的问题没有被理解,但你需要的是一个从三个不同的模型下拉列表,因为我猜...

在您自己的域中尝试此操作:

var dataForDL = _db.ModelName.Select(a => new
                {
                   Text = a.PersonName +" "+ a.Evidence.Name +" "+ a.City.CityName,
                   Value = a.Id
                }).ToList();
ViewBag.DropdownListForModel = new SelectList(dataForDL, "Value", "Text");

在view.cshtml中

@Html.DropDownList("DropdownListForModel", null, "-- Please Select Something --", htmlAttributes: new { @class = "form-control" })
 类似资料:
  • 我使用剑道网格内联编辑模式,编辑后,我需要刷新我的DropDownList的数据源。 原因是我的KendoGrid应该添加和编辑DropDownList使用的数据。我在编辑KendoGrid上的数据方面没有问题,在下面代码的帮助下,我刷新了DropDownList上的数据。 是我的DropDownList的ID 即使我编辑DropDownList上已经选择的数据,一切都工作正常。但是问题是在Ken

  • 问题内容: 大多数网站都需要某种方式来显示用户首选时区中网站上的日期。以下是我找到的两个列表,然后是使用 PHP 5中内置的PHP DateTime类的一种方法。 我需要帮助,以了解在尝试从注册用户那里获取UTC偏移量时,最好使用哪种方法。 一: 或使用PHP友好值: 或仅使用PHP本身: 似乎最后一个将是最安全的,因为它将随着使用的PHP版本而增长。您还可以在需要时将时区与城市名称关联时翻转该数

  • 增加下拉列表在到按钮上,确保 data-activates 属性匹配 <ul> 标签的 id,你可以增加分隔线通过 <li class="divider"></li> 标签。 <!-- Dropdown Trigger --> <a class='dropdown-button btn' href='#' data-activates='dropdown1'>单击我</a> <!-- D

  • 我正在使用npm模块编辑数据表单。下面是我的API响应示例: 下面是编辑组件所需的代码行 我需要显示下拉列表中选择的公司名称的现有值。

  • 实现下拉列表(Combo Box)功能,可以用作下拉单选框。 [Code4App.com]

  • 本文向大家介绍Element UI的表格,点击编辑跳转到编辑页面,编辑完成返回到列表页面,还返回到原分页列表相关面试题,主要包含被问及Element UI的表格,点击编辑跳转到编辑页面,编辑完成返回到列表页面,还返回到原分页列表时的应答技巧和注意事项,需要的朋友参考一下 Element UI的表格,点击编辑跳转到编辑页面,编辑完成返回到列表页面,还返回到原分页列表 作者:2443174881