亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

發布時清除綁定屬性

發布時清除綁定屬性

C#
小唯快跑啊 2023-09-16 15:56:17
如何清除這些屬性上的綁定,以便我嘗試在 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();


查看完整回答
反對 回復 2023-09-16
  • 1 回答
  • 0 關注
  • 135 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號