我测试了我的应用程序,在测试时我发现了一个错误,我认为它来自 ViewBage。我有 500 名医生和专业的列表,当我想编辑电话、地址等时,下拉列表会显示列表中的第一个 SpeciltyName,因此它不会保存医生的 SpeciltyName 您可以查看下面的图片以更好地理解
联系人控制器.cs
// GET: Contacts/Edit/5
public async Task<ActionResult> Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Contact contact = await db.Contacts.FindAsync(id);
if (contact == null)
{
return HttpNotFound();
}
ViewBag.TypeId = new SelectList(db.ContactTypes, "Id", "Name", contact.TypeId);
ViewBag.CategoryId = new SelectList(db.ContactCategories.Where(s => s.Name != "Attorney" && s.Name != "Law Firm"), "Id", "Name", contact.CategoryId);
ViewBag.ConCompanyId = new SelectList(db.Contacts.Where(s => s.ContactCategory.Name == "Insurance Carrier" || s.ContactCategory.Name == "Facility"), "Id", "Firstname");
return View(contact);
}
// POST: Contacts/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Edit([Bind(Include = "Id,UserId,Title,Firstname,Lastname,isCompany,CategoryId,TypeId,DateOfBirth,Address1,Address2,City,State,Zip,Email,Mobile,Phone,Website,Country,LocationGPS,Gender,Notes,Latitude,Longitude")] Contact contact)
{
if (ModelState.IsValid)
{
db.Entry(contact).State = EntityState.Modified;
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
}
任何帮助家伙?
收到一只叮咚
相关分类