iT邦幫忙

0

Viewbag問題請教

是這樣的,我做了一個表單,按下儲存後會出現儲存成功的提示

如下圖

https://ithelp.ithome.com.tw/upload/images/20190212/201101323Hh9oQrAdf.png

今日我想做一個新的提示,如果沒金額就會顯示"請計價"這個提示

但我目前失敗,想請問我該如何處理?

這是我新增相關的controller

  public ActionResult AddOrUpdate(HomeVisitViewModel model)
        {
            if(!ModelState.IsValid)
            {
                ViewBag.SaveResult = false;
                return View("HomeVisitEdit", model);
            }
            PD_HOME_VISIT pdhomevisit = new PD_HOME_VISIT();
            HomeVisitService hvsrvc = new HomeVisitService();

            bool saveResult = false;
            bool isAdd = false;
         
            //如果GUID空值或null就進行新增動作
            if (String.IsNullOrWhiteSpace(model.GUID) || new Guid(model.GUID) == Guid.Empty)
            {
                isAdd = true;          

            }
            if (model.NUTRITIONAL_SUPPLEMENT == "1")
            {
                model.NUTRITIONAL_SUPPLEMENT_CODE = string.Join(",", model.NUTRITIONAL_SUPPLEMENT_CODES.ToArray());
            }
            if (model.HOME_CARE_CODES != null) model.HOME_CARE_CODE = string.Join(",", model.HOME_CARE_CODES.ToArray());
            if (model.LIQUID_EXCHANGE_CODES != null) model.LIQUID_EXCHANGE_CODE = string.Join(",", model.LIQUID_EXCHANGE_CODES.ToArray());
            if (model.LE_PREPARE_CODES != null) model.LE_PREPARE_CODE = string.Join(",", model.LE_PREPARE_CODES.ToArray());
            if (model.LE_LIQUID_EXCHANGE_CODES != null) model.LE_LIQUID_EXCHANGE_CODE = string.Join(",", model.LE_LIQUID_EXCHANGE_CODES.ToArray());
            if (model.END_LE_LIQUID_EXCHANGE_CODES != null) model.END_LE_LIQUID_EXCHANGE_CODE = string.Join(",", model.END_LE_LIQUID_EXCHANGE_CODES.ToArray());
            if (model.PD_RECORD_CODES != null) model.PD_RECORD_CODE = string.Join(",", model.PD_RECORD_CODES.ToArray());
            if (model.CATHETER_OUTLET_CODES != null) model.CATHETER_OUTLET_CODE = string.Join(",", model.CATHETER_OUTLET_CODES.ToArray());
            if (model.DS_STOIRAGE_CODES != null) model.DS_STOIRAGE_CODE = string.Join(",", model.DS_STOIRAGE_CODES.ToArray());
            if (model.ORDER_COMOLIANCE_CODES != null) model.ORDER_COMOLIANCE_CODE = string.Join(",", model.ORDER_COMOLIANCE_CODES.ToArray());

            model.VISITDATE = DateHelper.ToDate(model.VisitDateString);
            model.HD_DATE = DateHelper.ToDate(model.HD_DateString);
            model.PD_DATE = DateHelper.ToDate(model.PD_DateString);
            model.FIRST_PD_PLACE_DATE = DateHelper.ToDate(model.First_PD_Place_Date_String);
            model.PERITONITIS_DATE = DateHelper.ToDate(model.Peritionitis_Date_String);
            model.EXIT_SITE_INFECTION_DATE = DateHelper.ToDate(model.Exit_Site_Infection_String);

            pdhomevisit = model.ToHomeVisit(SessionUserInfo().UserID);
            if (isAdd)
            {
                saveResult = hvsrvc.AddHomeVisit(pdhomevisit);
            }
            else
            {
                saveResult = hvsrvc.UpdateHomeVisit(pdhomevisit);
            }
          
            ViewBag.SaveResult = saveResult;
          
            HomeVisitViewModel newmhomevisit = GetHomeViewModel(pdhomevisit.GUID.ToString());
          
            newmhomevisit.Assess();
            return View("HomeVisitEdit", newmhomevisit);
        }

儲存相關的前端部分

    $(document).ready(function () {
        var saveResult = '@ViewBag.SaveResult';
        if (saveResult.toLowerCase() == 'true') {
            var saveResultMessage = '@ViewBag.SaveResultMessage';
            if (saveResultMessage == '') saveResultMessage = '儲存成功';
            $bui.alertOK(saveResultMessage);
        }
        else if (saveResult.toLowerCase() == 'false') {
            var saveResultMessage = '@ViewBag.SaveResultMessage';
            if (saveResultMessage == '') saveResultMessage = '儲存失敗';
            $bui.alertError(saveResultMessage);
        }                
    });
暐翰 iT邦大師 1 級 ‧ 2019-02-12 21:24:50 檢舉
後端有報錯? 還是瀏覽器打開console有錯誤訊息?

尚未有邦友回答

立即登入回答