Asp.net-Mvc-2
如何在 ASP.NET MVC2 中列舉 formcollection
我之前在使用How can a formcollection be enumerated in ASP.NET MVC? 的實現,但現在我在 VS2010 和 MVC2 上抱怨:
錯誤 1 無法將類型“System.Web.Mvc.IValueProvider”隱式轉換為 'System.Collections.Generic.IDictionary'。一個 存在顯式轉換(您是否缺少演員表?) C:\~\ProjectMVC\Controllers\TheController.cs 行 ProjectMVC程式碼是…
IDictionary<string, ValueProviderResult> tmpCollection = collection.ToValueProvider(); for (int j = 1; j <= noprops; j++) { string shopNmTmp = (from t in tmpCollection where t.Key.StartsWith(j + ".discount.sname." + j) select t.Value.AttemptedValue).First(); string shopCdTmp = (from t in tmpCollection where t.Key.StartsWith(j + ".discount.sref." + j) select t.Value.AttemptedValue).First(); ...當我不看的時候發生了什麼變化;這可以編譯、工作和執行,在 MVC1 中沒有問題;但不會在 2 中編譯。
謝謝
更新
我在技術上只是使用以下方法解決了這個問題:
Dictionary<string, string> tmpCollection = collection.AllKeys.ToDictionary(k => k, v => collection[v]);反而。
但我仍然對為什麼它在版本之間發生變化感興趣。
我在技術上只是使用以下方法解決了這個問題:
Dictionary<string, string> tmpCollection = collection. AllKeys.ToDictionary(k => k, v => collection[v]);收集後添加換行符。用於格式化