abp(net core)+easyui+efcore實作倉儲管理系統目錄
abp(net core)+easyui+efcore實作倉儲管理系統——ABP總體介紹(一)
abp(net core)+easyui+efcore實作倉儲管理系統——解決方案介紹(二)
abp(net core)+easyui+efcore實作倉儲管理系統——領域層創建物體(三)
abp(net core)+easyui+efcore實作倉儲管理系統——定義倉儲并實作 (四)
abp(net core)+easyui+efcore實作倉儲管理系統——創建應用服務(五)
abp(net core)+easyui+efcore實作倉儲管理系統——展現層實作增刪改查之控制器(六)
abp(net core)+easyui+efcore實作倉儲管理系統——展現層實作增刪改查之串列視圖(七)
abp(net core)+easyui+efcore實作倉儲管理系統——展現層實作增刪改查之增刪改視圖(八)
abp(net core)+easyui+efcore實作倉儲管理系統——展現層實作增刪改查之選單與測驗(九)
abp(net core)+easyui+efcore實作倉儲管理系統——多語言(十)
abp(net core)+easyui+efcore實作倉儲管理系統——使用 WEBAPI實作CURD (十一)
abp(net core)+easyui+efcore實作倉儲管理系統——選單-上 (十六)
abp(net core)+easyui+efcore實作倉儲管理系統——EasyUI前端頁面框架 (十八)
abp(net core)+easyui+efcore實作倉儲管理系統——EasyUI之貨物管理一 (十九)
abp(net core)+easyui+efcore實作倉儲管理系統——EasyUI之貨物管理二 (二十)
abp(net core)+easyui+efcore實作倉儲管理系統——EasyUI之貨物管理三 (二十一) abp(net core)+easyui+efcore實作倉儲管理系統——EasyUI之貨物管理四 (二十二) abp(net core)+easyui+efcore實作倉儲管理系統——EasyUI之貨物管理五 (二十三)在上一篇 abp(net core)+easyui+efcore實作倉儲管理系統——EasyUI之貨物管理五 (二十三) 文章中,我們修正了一些BUG,讓貨物資訊管理的前端與后臺功能基本實作了我們所要,現在我們運行起應用程式看看新增功能,
十五、新增貨物資訊
繼續來實作我們的貨物資訊管理功能,之前我們已經實作了串列功能,現在我們來實作貨物資訊的增加功能,
1. 在Visual Studio 2017的“解決方案資源管理器”中,右鍵單擊在領域層“ABP.TPLMS.Web.Core”專案中的Controller目錄, 找到TPLMSControllerBase檔案,添加一個新的方法JsonEasyUIResult,此方法用來實作當我們完成了增加貨物資訊之后,回傳給前端相關資訊,代碼如下,
protected dynamic JsonEasyUIResult(int id,string result) { string strId = string.Empty; if (id>0) { strId = id.ToString(); } var obj = new { result = result, Id = strId }; var json = ABP.TPLMS.Helpers.JsonHelper.Instance.Serialize(obj); return json; }2. 在Visual Studio 2017的“解決方案資源管理器”中,右鍵單擊在展示層“ABP.TPLMS.Web.Mvc”專案中的Controller目錄, 找到CargoController檔案,添加一個新增方法,代碼如下,
public ActionResult Add(CargoDto createDto) { var json = string.Empty; string result = "NO"; if (createDto == null) { json = JsonEasyUIResult(0, result); return Content(json); } try { var cargo = ObjectMapper.Map<CreateUpdateCargoDto>(createDto); // TODO: Add logic here var obj = _cargoAppService.Create(cargo); int id = obj.GetAwaiter().GetResult().Id; if (obj != null) { json = JsonEasyUIResult(id, "OK"); } else { json = JsonEasyUIResult(0,result); } } catch { } return Content(json); }
3.在Visual Studio 2017中按F5運行應用程式,
4.在瀏覽器中的地址欄中輸入“http://localhost:5000/”,然后輸入管理員用戶名進行登錄,
5.在主界面的選單中,選擇“Business->貨物管理”選單項,瀏覽器中呈現一個貨物資訊串列與四個按鈕,如下圖,關于選單的生成可以參見文章(abp(net core)+easyui+efcore實作倉儲管理系統——選單-上 (十六) 與 abp(net core)+easyui+efcore實作倉儲管理系統——選單-下(十七) ),

6.新增貨物:點擊“添加”按鈕,彈出一個“添加貨物”的操作界面,如下圖中所示,

7.在輸入相應的貨物資訊之后,點擊“保存”按鈕 ,在彈出的確認對話框中點擊“確定”按鈕,在彈出的“保存成功”確認對話框中點擊“確定”按鈕,

8.然后系統就沒有任何反應,沒有彈出任何提示資訊,查詢資料也沒有發現添加新資料,我們在瀏覽器中按F12,然后發現原來報錯了,如下圖,

具體錯誤資訊如下:
An unhandled exception occurred while processing the request.
AbpValidationException: Method arguments are not valid! See ValidationErrors for details.
Abp.Runtime.Validation.Interception.MethodInvocationValidator.ThrowValidationError() in MethodInvocationValidator.cs, line 118
9.原來是ABP的一個校驗例外,ABP的兩個特性EnableValidation和DisableValidation 用來控制validation,我們在Add方法上面添加兩個特性[HttpPost]與[DisableValidation],
[HttpPost] [DisableValidation] public ActionResult Add(CargoDto createDto) {… 代碼見第2步,}
10.重新從第3步到第7步,這次保存成功,見下圖,
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/98031.html
標籤:.NET Core
上一篇:ASP.NET Core 3.0 : 二十八. 在Docker中的部署以及docker-compose的使用
下一篇:我來告訴你:VS2019開發ASP.NET Core 3.0 Web專案,修改視圖后,重繪瀏覽器看不到修改后的效果怎么處理
