# ★★★★★ ModelState 的陷阱 (乾!) ###### tags: `被玩壞了` ## 案例說明 ### Model  ### View  ### Controller  ### 流程說明 1. 在 Step1 下一步到 Step2 的時候**更改 CurrentStep 為 Step2**,這時候在 **Step2 的 View 的 CurrentStep,還是 Step1 !** 2. 在 Step2 的頁面按下上一步,在 View 中使用 JS 將 ActionIsPrevious 設為 true,將資料 Post 回 Action,並**將 ActionIsPrevious 設回 False、CurrentStep 改回 Step1 後,導回 Step1 的頁面** 3. 這時候在 Step1 的 View 的 **ActionIsPrevious,還是 true !** ## 都是 ModelState 的臭(錯) 追了很久才發現,即使你在 Action 中寫了 model.ActionIsPrevious = false; 她還是不賞臉(喂 因為你的 ModelState 中有高富帥 (喂喂 **ModelState 中如果有 ActionIsPrevious 的參數,她會優先選擇 ModelState 的資料,而不是你寫的!** 所以這時候該怎麼辦呢? 把高富帥幹掉,抱得美人歸 ## 怎麼幹掉 ModelState -----> Remove  你成功幹掉高富帥了,能不能獲得美人就要看你自己了 **( 把值設定好 )**
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up