是這樣的我做了一個PartialView想給別的頁面使用
這個view CRUD皆可執行,資料庫裡的資料也有成功修改,只有
回傳頁面有問題,想請問該如何處理?
PartialView 相關controller
//顯示全部資料
public class PDNurseRecordController : BaseController
{
// GET: PDNurse/PDNurseRecord
public ActionResult PDNurseRecordList(PDNurseRecordQueryViewModel model)
{
if (TempData["DeleteResult"] != null)
{
ViewBag.DeleteResult = TempData["DeleteResult"];
}
if (!String.IsNullOrWhiteSpace(model.StartDateString))
{
model.StartDate = DateHelper.ToDate(model.StartDateString);
}
if (!String.IsNullOrWhiteSpace(model.EndDateString))
{
model.EndDate = DateHelper.ToDate(model.EndDateString);
}
PatInfoSession pat = SessionPatInfo();
PDNurseRecordService pdn = new PDNurseRecordService();
model.PDNurseRecords = pdn.FindNRecId(pat.PatGuid, model.StartDate, model.EndDate);
if (model.PDNurseRecords == null) model.PDNurseRecords = new List<PD.PDNurse.Models.PDNurseRecordListDto>();
model.AdjustFromView();
return PartialView(model);
}
public string GetUserGuid()
{
return SessionUserInfo().UserGuid;
}
//新增頁面
public ActionResult PDNurseRecordAdd()
{
UserInfoSession user = SessionUserInfo();
PatInfoSession pat = SessionPatInfo();
PDNurseRecordViewModel model = new PDNurseRecordViewModel();
model.CID = user.CID;
model.PAT_GUID = pat.PatGuid;
model.CRE_UID = user.UserID;
model.NURSE_EMP_ID = user.UserEmpID;
model.MOD_UID = user.UserID;
model.RECORD_DATETIME = DateTime.Now;
model.AdjustToView();
return View("PDNurseRecordEdit", model);
}
//編輯頁面
public ActionResult PDNurseRecordEdit(string uid, string patSchGuid)
{
if (patSchGuid != null && patSchGuid == "undefined") patSchGuid = "";
PDNurseRecordViewModel model = GetHDNurseRecordViewMidel(uid);
model.PatScheduleGuid = patSchGuid;
//model.RecordDateString = DateHelper.ToDate(model.RECORD_DATETIME);
//model.RecordTimeString = DateHelper.ToTime(model.RECORD_DATETIME);
model.AdjustFromView();
return View("PDNurseRecordEdit", model);
}
private PDNurseRecordViewModel GetHDNurseRecordViewMidel(string Guid)
{
PDNurseRecordService pdn = new PDNurseRecordService();
HD_NURSE_RECORD hdnr = pdn.FindGuid(Guid);
PDNurseRecordViewModel mdnr = new PDNurseRecordViewModel();
mdnr.FromNurseRecord(hdnr);
return mdnr;
}
//新增或編輯動作判斷
public ActionResult AddOrUpdate(PDNurseRecordViewModel model)
{
if (!ModelState.IsValid)
{
ViewBag.SaveResult = false;
return View("PDNurseRecordEdit", model);
}
HD_NURSE_RECORD hdnr = new HD_NURSE_RECORD();
PDNurseRecordService pdn = new PDNurseRecordService();
model.RECORD_DATETIME = DateHelper.ToDateTime(model.RecordDateString, model.RecordTimeString);
bool saveResult = false;
bool isAdd = false;
if (String.IsNullOrWhiteSpace(model.GUID) || new Guid(model.GUID) == Guid.Empty)
{
isAdd = true;
model.GUID = Guid.NewGuid().ToString();
}
hdnr = model.ToNurseRecord(GetUserGuid());
if (isAdd)
{
saveResult = pdn.AddNRec(hdnr);
}
else
{
saveResult = pdn.UpdateNrec(hdnr);
}
ViewBag.SaveResult = saveResult;
return RedirectToAction("OpdEvalEdit", "OpdEval");
//return View("PDNurseRecordEdit", model);
}
//刪除
public ActionResult PDNurseRecordDelete(string id)
{
PDNurseRecordService pdn = new PDNurseRecordService();
TempData["DeleteResult"] = pdn.RemovehNrec(id);
return RedirectToAction("OpdEvalEdit");
}
//欲使用PartialView 的controller
public class OpdEvalController : BaseController
{
public ActionResult OpdEvalAdd()
{
UserInfoSession user = SessionUserInfo();
PatInfoSession pat = SessionPatInfo();
OpdEvalViewModel model = new OpdEvalViewModel();
model.OpdEval.CID = user.CID;
model.OpdEval.PatGUID = pat.PatGuid;
model.OpdEval.ModUid = user.UserID;
model.OpdEval.CreUid = user.UserID;
//model = SetOptions(model);
return View("OpdEvalEdit", model);
}
}
PartialView畫面
欲使用PartialView畫面
這是兩個不同的controller 及view
PartialView的controller是PDNurseRecord,功能是護理紀錄
欲使用PartialView的controller是OpdEval,功能是門診評估
我想請問的是我在門診評估裡新增護理紀錄,那要怎麼做才能在護
理紀錄新增刪除修改後還能回到門診評估這個頁面,我做完這些動
作都會出現錯誤,但其實資料庫的資料都有成功
的變動到,所以想請問該如何處理?
在資料庫資料更新後使用 RedirectToAction 或 Redirect 方法將使用者導向回門診評估頁面。
假設在你的 OpdEvalController 中有一個 Action 方法叫做 "ViewEvaluation",那麼你可以在 PDNurseRecordController 的新增、修改、刪除資料後使用 RedirectToAction 方法將使用者導向回門診評估頁面。
[HttpPost]
public ActionResult CreateRecord(PDNurseRecord record)
{
// 新增資料到資料庫
// 將使用者導向回門診評估頁面
return RedirectToAction("ViewEvaluation", "OpdEval");
}
[HttpPost]
public ActionResult UpdateRecord(PDNurseRecord record)
{
// 更新資料庫中的資料
// 將使用者導向回門診評估頁面
return RedirectToAction("ViewEvaluation", "OpdEval");
}
[HttpPost]
public ActionResult DeleteRecord(int recordId)
{
// 從資料庫中刪除資料
// 將使用者導向回門診評估頁面
return RedirectToAction("ViewEvaluation", "OpdEval");
}
範例程式僅供參考,你需要根據自身情況斟酌修改。