我想把视图中得到的数据加进一个新表中,但不会加,求大神知道
这是我想把数据加进去的表
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); }
巧了。朋友,我也正在做,和你差不多,新人。
久违的net代码,看到好有亲切感。
没有人吗。