ValueProvider 不包含 TryGetValue 的定义
在我的应用程序中,我尝试从 DateTime 字段中拆分日期和时间,以便我可以在日期上放置 jQuery 日期选择器。我发现 Hanselman 的用于分割日期时间的代码,但是我在 上收到编译错误bindingContext.ValueProvider.TryGetValue(modelName, out valueResult);
。我得到的错误是:
错误 3“System.Web.Mvc.IValueProvider”不包含“TryGetValue”的定义,并且找不到接受“System.Web.Mvc.IValueProvider”类型的第一个参数的扩展方法“TryGetValue”(您缺少 using 指令或程序集引用吗?) C:\Documents and Settings\xxx\My Documents\Visual Studio 2008\Projects\MyProject\Project\Helpers\DateAndTimeModelBinder.cs 83 42 Project
我缺少什么?我创建了一个新类并将其代码放在我项目的 Helpers 文件夹中。
In my application, I am trying to split the Date and Time from and DateTime field so I can put a jQuery date picker on the date. I found Hanselman's code for splitting the DateTime, however I get a compile error on bindingContext.ValueProvider.TryGetValue(modelName, out valueResult);
. The error I get is:
Error 3 'System.Web.Mvc.IValueProvider' does not contain a definition for 'TryGetValue' and no extension method 'TryGetValue' accepting a first argument of type 'System.Web.Mvc.IValueProvider' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\xxx\My Documents\Visual Studio 2008\Projects\MyProject\Project\Helpers\DateAndTimeModelBinder.cs 83 42 Project
What am I missing something? I created a new class and put his code in a Helpers folder in my project.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TryGetValue()
不是System.Web.Mvc.IValueProvider
的成员。我怀疑他有一个自定义扩展,看起来像这样:Update
TryGetValue()
不是扩展方法,而是它的方法类型 IDictionary
。正如 @mootinator 所指出的,自 MVC1 以来,BindingContext.ValueProvider 的类型已发生变化。您可以忽略对TryGetValue()
的调用,而是调用GetValue()
并检查结果是否为 null。我不确定它是否会抛出异常,因为我还没有测试过,所以先尝试一下。TryGetValue()
is not a member ofSystem.Web.Mvc.IValueProvider
.I suspect he has a custom extension which looks something like:Update
TryGetValue()
is not an extension method, but rather it is a method on the type IDictionary<T,U>
. The type ofbindingContext.ValueProvider
has changed since MVC1 as @mootinator indicated. It's possible you can just ignore the call toTryGetValue()
and instead callGetValue()
and check the result for null. I'm not sure if it will throw an exception as I haven't tested it, so try that first.前几天我在尝试效仿汉塞尔曼的例子时遇到了这个问题。这不是 MVC2 示例。 TryGetValue 不起作用和/或不再需要。试试这个链接:
http://forums.asp.net/p/1529895/3706154.aspx
我从 Hanselman 的 GetA 方法创建了一个 MVC2 扩展方法来替换,尽管我不确定它是否按预期工作,因为它没有解决我的独特问题,这实际上与日期没有任何关系或时间。
I had this problem trying to follow Hanselman's example the other day. It's not an MVC2 example. TryGetValue doesn't work and/or isn't needed anymore. Try this link:
http://forums.asp.net/p/1529895/3706154.aspx
I created an MVC2 extension method from Hanselman's GetA method to replace, though I'm not sure whether it works as intended, since it didn't solve my unique problem, which didn't actually have anything to do with date or time.