如何清除這些屬性上的綁定,以便我嘗試在 onpost 方法中進行的更改生效?我在 ShipmentModel 中有 6 個綁定屬性:[BindProperty(SupportsGet = true)] public ShipmentModel Shipment { get; set; }public class ShipmentModel{ public string CurrentShipDt1 { get; set; } public int CurrentShipQty1 { get; set; } public string CurrentShipDt2 { get; set; } public int CurrentShipQty2 { get; set; } public string CurrentShipDt3 { get; set; } public int CurrentShipQty3 { get; set; }}在我的 onget 中,我運行了一些 linq 查詢,它正確地將結果發布到這些屬性:public async Task<IActionResult> OnGetAsync(string partNo, string requestStatus, string supplier, string searchString){ // Find the current shipment info for this part CmtPartShipSchedule = await _context.CmtPartShipSchedules .OrderByDescending(m => m.EnterDt) .FirstOrDefaultAsync(m => m.PartNo == partNo); if (CmtPartShipSchedule != null){ var shipDtQuery = (from c in _context.CmtPartShipments where CmtPartShipSchedule.Id == c.CmtPartShipScheduleId orderby c.ShipDt descending select c.ShipDt).ToList(); List<DateTime> CmtPartShipDts = shipDtQuery; var shipQtyQuery = (from c in _context.CmtPartShipments where CmtPartShipSchedule.Id == c.CmtPartShipScheduleId orderby c.ShipDt descending select c.ShipQty).ToList(); List<int> CmtPartShipQtys = shipQtyQuery; CmtPartShipment = await _context.CmtPartShipments .FirstOrDefaultAsync(m => m.CmtPartShipScheduleId == CmtPartShipSchedule.Id); int shipCount = shipDtQuery.Count();問題出在我創建的 onpost 方法上 - 它應該清除通過單擊按鈕在我的 onget 中設置的值的所有屬性。但是,我無法讓它做到這一點。此時,它正確地運行了我的方法,但沒有發布結果(因為模型綁定正在覆蓋我試圖進行的這些更改,我認為)。我嘗試過的:最初我使用的是 return Page(); 這里的類似帖子告訴我將其更改為返回 RedirectToPage(),但仍然沒有任何變化。另外,參考這篇文章,我嘗試使用 ModelState.Remove 來“清除綁定”,仍然沒有變化。
1 回答

侃侃無極
TA貢獻2051條經驗 獲得超10個贊
這有效(我在修改值之前清除模型狀態,而不是之后?。?/p>
Shipment.CurrentShipDt1?=?null;?Shipment.CurrentShipQty1?=?0; Shipment.CurrentShipDt2?=?null;?Shipment.CurrentShipQty2?=?0; Shipment.CurrentShipDt3?=?null;?Shipment.CurrentShipQty3?=?0; Shipment.CurrentShipDt4?=?null;?Shipment.CurrentShipQty4?=?0; Shipment.CurrentShipDt5?=?null;?Shipment.CurrentShipQty5?=?0; ModelState.Clear();return?Page();
- 1 回答
- 0 關注
- 135 瀏覽
添加回答
舉報
0/150
提交
取消