首页 新闻 会员 周边

本人小白,求大神指导一下怎么绑定数据

0
悬赏园豆:100 [已关闭问题] 关闭于 2018-01-19 16:52

我想把视图中得到的数据加进一个新表中,但不会加,求大神知道

这是我想把数据加进去的表

 public class registers {
        public int ID { get; set; }
        public int patientID { get; set; }
        public int MrItemID { get; set; }
        public int doctorID { get; set; }
        public virtual patients patient { get; set; }
        public virtual doctors doctor { get; set; }
        public virtual MrItems MrItems { get; set; }

    }

这是得到数据的那个视图

<h4>病人</h4>
<hr />
<dl class="dl-horizontal">
    <dt>
        @Html.DisplayNameFor(model => model.patient_name)
    </dt>

    <dd>
        @Html.DisplayFor(model => model.patient_name)
    </dd>

    <dt>
        @Html.DisplayNameFor(model => model.patient_ade)
    </dt>

    <dd>
        @Html.DisplayFor(model => model.patient_ade)
    </dd>

    <dt>
        @Html.DisplayNameFor(model => model.patient_sex)
    </dt>

    <dd>
        @Html.DisplayFor(model => model.patient_sex)
    </dd>

    <dt>
        @Html.DisplayNameFor(model => model.patient_num)
    </dt>

    <dd>
        @Html.DisplayFor(model => model.patient_num)
    </dd>
</dl>   
    
    <div class="form-group">
        <h4>选择医生</h4>
        <hr />
        <p>@Html.DropDownList("searchdoctor", " ")</p>
        <p>@Html.ActionLink("挂号", "Index")</p>
    </div>
</div>
<p>
    @Html.ActionLink("编辑", "Edit", new { id = Model.ID }) |
    @Html.ActionLink("返回列表", "Index")
</p>

我想通过得到的医生名字,查到医生id,然后将得到的病人id和医生id插入表里

尝试写了一些,不会写卡住了,求大神指导

这是控制器里的代码

 public ActionResult Register(int? id, string searchdoctor)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            patients patients = db.patients.Find(id);
            var doctorList = new List<string>();
            var doctorQry = from d in db.doctors
                            orderby d.doctor_name
                            select d.doctor_name;
            var doctor = from m in db.doctors
                         select m.doctor_name;
            doctorList.AddRange(doctorQry.Distinct());
            ViewBag.searchdoctor = new SelectList(doctorList);
            if (patients == null)
            {
                return HttpNotFound();
            }
            return View(patients);
        }
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Register([Bind(Include = "ID,patient_name,patient_ade,patient_sex,patient_num")] patients patients
           /*,[Bind(Include = "ID,doctor_name,user_name,Password")]doctors doctors
         ,[Bind(Include = "ID,patientID,MrItemID,doctorID")]registers register*/)
        {
            //int  patientID = patients.ID;
            //string doctorname = doctors.doctor_name;

            if (ModelState.IsValid)
            {
                db.Entry(patients).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(patients);
        }
xingcs的主页 xingcs | 初学一级 | 园豆:4
提问于:2018-01-11 16:57
< >
分享
所有回答(3)
0

巧了。朋友,我也正在做,和你差不多,新人。

云--澈 | 园豆:202 (菜鸟二级) | 2018-01-11 17:06
0

久违的net代码,看到好有亲切感。

一脸沧桑的刘先生 | 园豆:204 (菜鸟二级) | 2018-01-11 18:14
0

没有人吗。

xingcs | 园豆:4 (初学一级) | 2018-01-19 16:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册